diff options
| author | Niklas Baumstark | 2012-01-27 21:45:01 +0100 | 
|---|---|---|
| committer | Niklas Baumstark | 2012-04-10 23:59:54 +0200 | 
| commit | f28edd6bcb2a84e7c36700af102006c95468a265 (patch) | |
| tree | d191854421e0cdac40894f38859e16b69bcba5d8 /lib/completion.js | |
| parent | 7eb205f7d45b72d793d9109848293555ba21ed51 (diff) | |
| download | vimium-f28edd6bcb2a84e7c36700af102006c95468a265.tar.bz2 | |
small changes
Diffstat (limited to 'lib/completion.js')
| -rw-r--r-- | lib/completion.js | 11 | 
1 files changed, 5 insertions, 6 deletions
| diff --git a/lib/completion.js b/lib/completion.js index b3e70516..58f140f9 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -63,19 +63,18 @@ var completion = (function() {        return null;      } -    /** Calculates a very simple similarity value between a :query and a :string. The current -     * implementation simply returns the cumulated length of query parts that are also found -     * in the string, raised to the power of 3. -     */ +    /** Calculates a very simple similarity value between a :query and a :string */      self.calculateRelevancy = function(query, str) {        query = self.normalize(query);        str   = self.normalize(str);        var sum = 0; +        // only iterate over slices of the query starting at an offset up to 10 to save resources        for (var start = 0; start < 20 && start < query.length; ++start) {          for (var i = query.length; i >= start; --i) {            if (str.indexOf(query.slice(start, i)) >= 0) { -            sum += (i - start) * (i - start); +            var length = i - start; +            sum += length * length;              break;            }          } @@ -173,7 +172,7 @@ var completion = (function() {    var htmlRegex = /<[^>]*>|&[a-z]+;/gi; -  /** Strips HTML tags and escape sequences using a naive regex replacement. Optionally, saves the stripped +  /** Strips HTML tags and entities using a naive regex replacement. Optionally, saves the stripped     * HTML tags in a dictionary indexed by the position where the tag should be reinserted. */    function stripHtmlTags(str, positions) {      if (!positions) | 
