Skip to content

Commit

Permalink
Bug 1664814: Limit the number of tokens to reduce calculate time. r=adw
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisuke Akatsuka committed Aug 23, 2021
1 parent 1cf3bc3 commit d26b894
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion browser/components/urlbar/UrlbarUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ var UrlbarUtils = {
highlightType == this.HIGHLIGHT.SUGGESTED ? 1 : 0
);
let compareIgnoringDiacritics;
for (let { lowerCaseValue: needle } of tokens) {
for (let i = 0, totalTokensLength = 0; i < tokens.length; i++) {
const { lowerCaseValue: needle } = tokens[i];

// Ideally we should never hit the empty token case, but just in case
// the `needle` check protects us from an infinite loop.
if (!needle) {
Expand Down Expand Up @@ -473,6 +475,12 @@ var UrlbarUtils = {
}
}
}

totalTokensLength += needle.length;
if (totalTokensLength > UrlbarUtils.MAX_TEXT_LENGTH) {
// Limit the number of tokens to reduce calculate time.
break;
}
}
// Starting from the collision array, generate [start, len] tuples
// representing the ranges to be highlighted.
Expand Down

0 comments on commit d26b894

Please sign in to comment.