From 4d54445a454dd3998587a53b5df4e93b33824a72 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Fri, 27 Aug 2021 11:16:47 +0200 Subject: [PATCH] util: improve `toUSVString` performance --- lib/internal/util.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/internal/util.js b/lib/internal/util.js index b4b27cefb98a3c..a3ecfb8837d1d3 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -17,10 +17,10 @@ const { Promise, ReflectApply, ReflectConstruct, - RegExpPrototypeExec, RegExpPrototypeTest, SafeMap, SafeSet, + StringPrototypeSearch, StringPrototypeReplace, StringPrototypeToLowerCase, StringPrototypeToUpperCase, @@ -60,12 +60,10 @@ const colorRegExp = /\u001b\[\d\d?m/g; // eslint-disable-line no-control-regex const unpairedSurrogateRe = /\p{Surrogate}/u; function toUSVString(val) { const str = `${val}`; - // As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are - // slower than `unpairedSurrogateRe.exec()`. - const match = RegExpPrototypeExec(unpairedSurrogateRe, str); - if (!match) + const index = StringPrototypeSearch(str, unpairedSurrogateRe); + if (index === -1) return str; - return _toUSVString(str, match.index); + return _toUSVString(str, index); } let uvBinding;