Bug 1371554 - Change .indexOf(...) == 0 to the more expressive .startsWith(...). r=mattn.
MozReview-Commit-ID: Jr3ALp6v2rM
--- a/toolkit/components/satchel/nsFormAutoComplete.js
+++ b/toolkit/components/satchel/nsFormAutoComplete.js
@@ -530,23 +530,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,