Issue 1561634: String searching performance improvement (original) (raw)
The current string searching (str.find) seems to use the simplest possible method of searching, which is simply comparing character by character. A simple speed improvement would be to take needle[-1] and start searching at haystack[len(needle)-1]. Then check again at haystack[len(needle)*2-1]. etc. If the last character doesn't match, then the rest of the string couldn't possibly match. I'm sure there are other methods of speeding up string searching but this seems like a pretty simple and easy improvement. If I have some time I will go ahead and try implementing it myself.