https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96197

--- Comment #2 from Erich Erstu <hyena at hyena dot net.ee> ---
Richard Biener, you were right. I optimized the implementation of all the
problematic constant expression functions similarly to the one seen below, and
the compilation time went down to practically zero with unnoticeable memory
consumption. This is simple enough workaround that I can actually put into use
for real.

// I added this proxy struct for faster lookups:
constexpr const struct NOUN_INDEX_TYPE {
    constexpr NOUN_INDEX_TYPE() : indices() {
        for (const noun_type &noun : noun_table) {
            indices[static_cast<size_t>(noun.index)] = &noun;
        }
    }
    const noun_type *indices[1024];
} NOUN_INDEX_TABLE;

constexpr const struct noun_type &NOUN(WORD index, const struct noun_type
*table_row =noun_table) {
    return *NOUN_INDEX_TABLE.indices[static_cast<size_t>(index)];
    /*
    for (;;) {
        if (table_row->index == index) return *table_row;

        if (table_row->index == WORD::NONE) return noun_lookup(WORD::NONE);

        ++table_row;
    }
    */

    //return table_row->index == index ? *table_row : (table_row->index ==
WORD::NONE ? noun_lookup(WORD::NONE) : NOUN(index, ++table_row));
}

Reply via email to