Skip to content

Commit 7bcd588

Browse files
committed
perf: Do not continue if URL not changed after a rule
1 parent 6280f78 commit 7bcd588

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

purlfy.js

+4
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ class Purlfy extends EventTarget {
348348
* @returns {Promise<[URL, boolean, Object]>} The new URL object, whether to continue and the mode-specific incremental statistics.
349349
*/
350350
async #applyRule(urlObj, rule, logFunc) {
351+
const originalUrl = urlObj.href;
351352
const mode = rule.mode;
352353
const increment = { ...Purlfy.#zeroStatistics }; // Incremental statistics
353354
const lengthBefore = urlObj.href.length;
@@ -518,6 +519,9 @@ class Purlfy extends EventTarget {
518519
const paramsCntAfter = urlObj.searchParams.size;
519520
increment.param += (["white", "black"].includes(mode)) ? (paramsCntBefore - paramsCntAfter) : 0;
520521
increment.char += Math.max(lengthBefore - urlObj.href.length, 0); // Prevent negative char count
522+
if (urlObj.href === originalUrl) {
523+
shallContinue = false; // Overwrite shallContinue if URL has not been changed
524+
}
521525
return [urlObj, shallContinue, increment];
522526
}
523527

0 commit comments

Comments
 (0)