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 363063 3b978477fa69
parent 363062 ff83c340468a
child 363064 c18268020e6e
push id91258
push usermozilla@noorenberghe.ca
push dateFri, 09 Jun 2017 09:30:07 +0000
treeherdermozilla-inbound@3b978477fa69 [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,