I have some code at the moment that looks like this:
#define ______ 0x0000
static const uint16_t plane0[256] = {
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
______, ______, ______, ______, ______, 0x039C, ______, ______,
______, ______, ______, ______, ______, ______, ______, ______,
...
};
#undef ______
uint16_t caseup(uint16_t wc)
{
return (plane0[wc] == 0x0000) ? wc : plane0[wc];
}
I would really like to replace that caseup
function with a simple return plane0[wc]
. The extra compare-and-branch might not be very expensive in the big picture, but certainly the code would be strictly more efficient if we got rid of it.
But I don't want to have to rewrite the table. Not even using a tool to rewrite it — I don't want our case-mapping table cluttered up with a lot of garbage hex values. I want the table to remain mostly pristinely macro-ized, with hex values only in the places that actually require non-identity case mappings.
What's the cleanest way to do this in C++11?