Bug 1371554 - Change .indexOf(...) == 0 to the more expressive .startsWith(...). r=mattn.
authorJonathan Guillotte-Blouin <jguillotteblouin@mozilla.com>
Tue, 06 Jun 2017 13:35:34 -0700
changeset 411316 3b978477fa6994be455c98c9404405aff3cfa37a
parent 411315 ff83c340468acd6c32f3802fe40bd0336930ea7f
child 411317 c18268020e6e77dd5872a423a080bb60e5065f3e
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattn
bugs1371554
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1371554 - Change .indexOf(...) == 0 to the more expressive .startsWith(...). r=mattn. MozReview-Commit-ID: Jr3ALp6v2rM
toolkit/components/satchel/nsFormAutoComplete.js
--- a/toolkit/components/satchel/nsFormAutoComplete.js
+++ b/toolkit/components/satchel/nsFormAutoComplete.js
@@ -510,23 +510,29 @@ FormAutoComplete.prototype = {
    * searchTokens -- array of tokens of the search string
    *
    * Returns: an int
    */
   _calculateScore(entry, aSearchString, searchTokens) {
     let boundaryCalc = 0;
     // for each word, calculate word boundary weights
     for (let token of searchTokens) {
-      boundaryCalc += (entry.textLowerCase.indexOf(token) == 0);
-      boundaryCalc += (entry.textLowerCase.includes(" " + token));
+      if (entry.textLowerCase.startsWith(token)) {
+        boundaryCalc++;
+      }
+      if (entry.textLowerCase.includes(" " + token)) {
+        boundaryCalc++;
+      }
     }
     boundaryCalc = boundaryCalc * this._boundaryWeight;
     // now add more weight if we have a traditional prefix match and
     // multiply boundary bonuses by boundary weight
-    boundaryCalc += this._prefixWeight * (entry.textLowerCase.indexOf(aSearchString) == 0);
+    if (entry.textLowerCase.startsWith(aSearchString)) {
+      boundaryCalc += this._prefixWeight;
+    }
     entry.totalScore = Math.round(entry.frecency * Math.max(1, boundaryCalc));
   }
 
 }; // end of FormAutoComplete implementation
 
 // nsIAutoCompleteResult implementation
 function FormAutoCompleteResult(client,
                                 entries,