News for hackers. Stuff that matters.
Re:Branch predictor: How many “if”s are too many? by simias on Thursday May 06, 2021 @02:59PM (#27067686)
I think that's the best solution (the only potential optimization I can think of would be to add a padding byte after every country to force 32bit alignment which would make the offset computation faster on some architectures, although probably not on x86).

Stylistically-wise I think the best solution would be to write the array like:

    const char countries[][3] = {
        [0] = "A1",
        [1] = "A0",
    };
This way the codes are explicit when you read the code and it makes editing the array a little easier. Unfortunately gcc only warns if you set the same index twice with -Wextra, it remains silent with -Wall.
Re:Branch predictor: How many “if”s are too many? by messe on Thursday May 06, 2021 @03:36PM (#27068109)
> This way the codes are explicit when you read the code

Good call. It might have caught the off-by-one mistake I made (the codes start from 1 and not 0 in the blog post). Maybe even switch to using an enum as our index instead of an int.