3 ms·
Yeah, it’s possible to change case while loading, but I’m not sure that’s gonna be much faster. But I’m sure it gonna be much harder. For non-ASCII strings, c
by Const-me 4y ago
Yeah, it’s possible to change case while loading, but I’m not sure that’s gonna be much faster.
But I’m sure it gonna be much harder.
For non-ASCII strings, converting case may change their length in bytes. You don’t even know in advance how much memory you need to transform 2GB of input text (or 1MB buffer if streaming). And if streaming, you need to be careful to keep code points together: with a naïve approach you gonna crash with a runtime exception when you split a single codepoint between chunks.
English words are 99.9% ASCII, but that remaining 0.1% like “naïve” is not. The C# standard library is doing the right thing for this use case. Specifically, for 99.9% of words the CI comparer will use the faster ASCII-only code to compare or hash, and only do the expensive shenanigans for small count of non-ASCII words.
Note how C# makes the implementation much simpler. A single parameter passed to the constructor of the Dictionary<string,Something> makes it implement case-insensitivity automagically.