Skip to content

Commit 336ce2b

Browse files
committed
Improve regex efficiency when trimming long ua string
https://blog.stevenlevithan.com/archives/faster-trim-javascript
1 parent 20a428c commit 336ce2b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/ua-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
},
9292
trim = function (str, len) {
9393
if (typeof(str) === STR_TYPE) {
94-
str = str.replace(/^\s+|\s+$/g, EMPTY);
94+
str = str.replace(/^\s\s*/, EMPTY).replace(/\s\s*$/, EMPTY);
9595
return typeof(len) === UNDEF_TYPE ? str : str.substring(0, UA_MAX_LENGTH);
9696
}
9797
};

0 commit comments

Comments
 (0)