4 ms·
In a project I did long ago (having nothing to do with a compiler) I was dealing with many text compares and two dozen keywords I heard of 'gperf' before but i
by levodelellis 4y ago
In a project I did long ago (having nothing to do with a compiler) I was dealing with many text compares and two dozen keywords
I heard of 'gperf' before but it wasn't giving me good results so I had to hand write my own solution. I quickly noticed many of the keywords start and end with the same few letters but the second and third last rarely matched up and when they did the word length was different
I ended up writing `memcpy(&myint, (input_ptr+input_size-4), 4)` then adding size to myint. I then had a unique int so I used a switch and did a memcmp on each case. Memcmp was expensive because many words and keywords were the same length and 20+ letters. The function went from the slowest to fastest on that change. If I had to rewrite it today I would use SIMD and a 16bit compare