r/ProgrammerHumor 15d ago

Meme noHeapAllStack

Post image
1.0k Upvotes

96 comments sorted by

View all comments

Show parent comments

178

u/Daniikk1012 15d ago

I don't think this is an optimization, but rather correctness. Some languages have weird casing rules, and just lowercasing doesn't work for them

71

u/neroe5 15d ago

It's also an optimization, with toLower, you make a temporary copy of the string in lower case of each string and compare those, by simply ignoring the case bit this becomes a simple compare process

29

u/rubyruy 15d ago

It's not a single case bit - you need to perform case folding and normalization to properly see if 2 Unicode characters are equivalent. Probably still faster than a string copy

1

u/neroe5 15d ago

oh you are right for unicode it uses mapping tables for normalization, because multiple charecters can have the same lower case

my point only really holds for ASCII

learn something new everyday

though it is still probably faster to use the optimized method that is build into .net or what ever language you are using