-
Notifications
You must be signed in to change notification settings - Fork 12
Description
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:
Function SortByName:Int(o1:Object, o2:Object)
Local p1:TProgrammeLicence = TProgrammeLicence(o1)
Local p2:TProgrammeLicence = TProgrammeLicence(o2)
If Not p2 Then Return 1
If Not p1 Then Return -1
'remove "ToLower" for case sensitive comparison
Local t1:String = p1.title.ToLower()
Local t2:String = p2.title.ToLower()
If t1 > t2
Return 1
ElseIf t1 < t2
Return -1
Else
Return p1.guid > p2.guid
EndIf
End Function
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) ?