Skip to content

Commit 1d91556

Browse files
committed
Refactor towards a for loop and .push while removing redundant check
```unshift``` is significantly slower than ```push```. Shift towards using ```push``` and remove a redundant conditional.
1 parent 0bd6221 commit 1d91556

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/raven.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,15 +642,15 @@ function isSetup() {
642642
function joinRegExp(patterns) {
643643
// Combine an array of regular expressions and strings into one large regexp
644644
// Be mad.
645-
var sources = [], i = patterns.length;
646-
while (i--) {
645+
var sources = [];
646+
for (var i = 0; i < patterns.length; i++) {
647647
if (isString(patterns[i])) {
648648
// If it's a string, we need to escape it
649649
// Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
650-
sources.unshift(patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"));
651-
} else if (!isUndefined(patterns[i]) && patterns[i] && patterns[i].source) {
650+
sources.push(patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"));
651+
} else if (patterns[i] && patterns[i].source) {
652652
// If it's a regexp already, we want to extract the source
653-
sources.unshift(patterns[i].source);
653+
sources.push(patterns[i].source);
654654
}
655655
// Intentionally skip other cases
656656
}

0 commit comments

Comments
 (0)