-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add string.HashLower() and string.Equals(other, caseSensitive) or other solution? #330
Comments
I definitely wouldn't want an additional hash stored in strings. Strings are used all over, and this would add overhead to all of them. For the relatively rare case of case-insensitive comparisons being needed (and even rarer, being a performance problem), that does seem worth the cost.
With what's currently available? Your code sample looks like you have (somewhat long-lived?) |
Regarding structs - for this your reflection branch needs to be rolled out as I serialize these kind of objects via reflection (Brucey's TPersistence) which does not work with structs in its current incarnation. Using a special "lookup-lowercase-copy" (which I mark as not necessary for serialization, so only used during "runtime) is an idea which I had too - but it of course would require a "synchronization" (title might change randomly - eg in my case containing actual score of a sports match too). So changes would require "compares" and invalidate the "lookup-lowercase-copy" on changes. This is why I thought a "in the core" solution would be the better approach - it hides away the issues you will face if you want a faster and lightweight "case insensitive compare". Maybe a "not the best but at least better" solution would be to provide a c-written function comparing passed strings case-insensitively - maybe even with handling "utf8" too (or for performance reasons provide two functions - for "normal, ignoring utf8" and one for "including utf8").
creates 2 new gc objects (the strings) for each compare it does. But I assume it could be "more lightweight / less gc stress" if we could do something like:
Of course this would not have the speed beenfits of the hash comparison but at least would avoid affecting the GC by outsourcing the comparison to C. |
That's why I suggested creating a struct that contains both. Then setting the title shouldn't require anything changes other than writing
That's what I was referring to at the start (preferrably with an |
For now any string comparison is already sped up by a "hash" (generated during compilation for defined strings and during runtime for others).
But what happens if you want to eg use a custom sort "by string value" in a case insensitive manner? Such a sort function would look like this:
So for each time an object is asked to get "compared with another" it will create a "to lower" string.
Couldn't we also get a "case-insensitive hash" or do you think this is too much (as it adds another property to all strings) ?
I know I could - in this example case - have "Field titleLowerCaseHash:Long" which I manually create and recreate on each "title"-change but it does not look "that smart" either.
Do you (others) have a suggestion on how to solve such stuff (a "performant" case insensitive sort implementable in the "custom sort function"-fashion BlitzMax offers) ?
The text was updated successfully, but these errors were encountered: