Skip to content

Commit 018277a

Browse files
authored
Merge pull request #8 from camillobruni/2024-11-22_regexp
Use regexp results
2 parents 7e9b4b1 + bfd6016 commit 018277a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

RexBench/Octane2/regexp.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,23 @@ function RegExpBenchmark() {
7272
if (array) {
7373
for (var i = 0; i < array.length; i++) {
7474
var substring = array[i];
75-
if (substring) sum += substring.length;
75+
if (substring) {
76+
sum += substring.length;
77+
sum += resultHash(substring)
78+
}
7679
}
7780
}
7881
return sum;
7982
}
83+
84+
function resultHash(substring) {
85+
let sum = 0;
86+
for (let j = 0; j < substring.length; j+=37)
87+
sum ^= substring.charCodeAt(j)
88+
sum ^= substring.charCodeAt(substring.length-1)
89+
return sum;
90+
}
91+
8092
var re0 = /^ba/;
8193
var re1 = /(((\w+):\/\/)([^\/:]*)(:(\d+))?)?([^#?]*)(\?([^#]*))?(#(.*))?/;
8294
var re2 = /^\s*|\s*$/g;

0 commit comments

Comments
 (0)