diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/completion.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/completion.js b/lib/completion.js index 5950a1ca..077dcc80 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -26,13 +26,20 @@ var completion = (function() { * Sample: match("codecodec","code.google.com/codec") would yield ["", "code", ".google.com/", "codec"] * * Note that this function matches the longest possible parts of a string and is therefore not very - * efficient. _Don't use this to check if a string matches a query_. Use `getMatcher(query).test(str)` - * instead. + * efficient. There it falls back to a more performant, but less accurate regex matching if the + * normalized query is longer than 10 characters. + * + * _Don't use this to check if a string matches a query_. Use `getMatcher(query).test(str)` instead. */ self.match = function(query, str) { query = self.normalize(query); if (query.length == 0) return str.length ? [str] : []; + if (query.length > 10) { + // for long query strings, the method is much too inefficient, so fall + // back to the more inaccurate regex matching + return self.getMatcher(query).exec(str).slice(1); + } for (var i = query.length; i >= 1; --i) { var part = query.slice(0, i); |
