So, I wrote an article a while ago demonstrating the huge performance gain using StringMap algorithm instead of regular expressions for straight forward string full matching. The main goal here is to improve performance for sequential string matching done on a single block of string or a string array.
The motivation here is simply performance, a lot of time difference comparing google's re to my StringMap implementation (seconds), you can read the article here https://gist.github.com/o-micron/f7c98226e5e0c81164fbc2704a855132
I guess swift would benefit from that time difference and I would love to hear back from the community wether this is going to play well with the upcoming schedule of improvements.
I apologize, StringMap is an algorithm developed to map a string into smaller arrays of features represented in floating point numbers. For simplicity, you can transform a long word into a single float that uniquely represents this word, which then is going to be easier to compare against other words or (float numbers as well). You may think of it like a hashmap, you hash each word into a unique representation.
Say you have a string s = "Swift is cool";
you can represent "Swift" in a float (0.0), "is" in a float (1.0) and "cool" in a float (2.0) for example.
And whenever you want to search for a word you simply try to compare numbers instead of character by character.
By RE2 I mean regular expressions version 2.0.
By fullmatch I mean fully matching a string with another string, example:
matching "Swift" with "Swift" will match but "Swift" with "Swift is cool" will not match.
Swift Strings are Unicode-aware, meaning two strings that compare equal may not have the same binary representation. They therefore can't be compared using a (non-Unicode-aware) hash function.