bevacqua / fuzzysearch

:crystal_ball: Tiny and blazing-fast fuzzy search in JavaScript
https://ponyfoo.com
MIT License
2.71k stars 87 forks source link

startsWith Optimization #28

Open mu-arch opened 1 year ago

mu-arch commented 1 year ago

I've made a minor optimization here to improve performance.

In this new code startsWith() can stop checking as soon as it finds a character that doesn't match, while the former equality comparison checks the entire string.

The behavior of startsWith() and the equality comparison operator are equivalent when the lengths of the needle and haystack are the same, which the if block assures us of.