diff options
| author | Niklas Baumstark | 2012-01-23 15:08:28 +0100 |
|---|---|---|
| committer | Niklas Baumstark | 2012-04-10 23:54:38 +0200 |
| commit | 59b096f2c4d9f5406cfa10f71b64887ef1e9fa49 (patch) | |
| tree | ab330afc04ff95b821804a11f4d8eece7facff49 /lib | |
| parent | de0a3607fd0a1e788d314f24894ba72315a64771 (diff) | |
| download | vimium-59b096f2c4d9f5406cfa10f71b64887ef1e9fa49.tar.bz2 | |
fall back to regex matching for long queries
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); |
