Skip to content

Commit f51c152

Browse files
authored
util: reduce javascript call for ToUSVString
PR-URL: #47192 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 8200304 commit f51c152

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

lib/internal/util.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,8 @@ const experimentalWarnings = new SafeSet();
6969

7070
const colorRegExp = /\u001b\[\d\d?m/g; // eslint-disable-line no-control-regex
7171

72-
const unpairedSurrogateRe =
73-
/(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/;
7472
function toUSVString(val) {
75-
const str = `${val}`;
76-
// As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are
77-
// slower than `unpairedSurrogateRe.exec()`.
78-
const match = RegExpPrototypeExec(unpairedSurrogateRe, str);
79-
if (!match)
80-
return str;
81-
return _toUSVString(str, match.index);
73+
return _toUSVString(`${val}`);
8274
}
8375

8476
let uvBinding;

src/node_util.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,12 @@ static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
322322

323323
static void ToUSVString(const FunctionCallbackInfo<Value>& args) {
324324
Environment* env = Environment::GetCurrent(args);
325-
CHECK_GE(args.Length(), 2);
325+
CHECK_GE(args.Length(), 1);
326326
CHECK(args[0]->IsString());
327-
CHECK(args[1]->IsNumber());
328327

329328
TwoByteValue value(env->isolate(), args[0]);
330329

331-
int64_t start = args[1]->IntegerValue(env->context()).FromJust();
332-
CHECK_GE(start, 0);
333-
334-
for (size_t i = start; i < value.length(); i++) {
330+
for (size_t i = 0; i < value.length(); i++) {
335331
char16_t c = value[i];
336332
if (!IsUnicodeSurrogate(c)) {
337333
continue;

0 commit comments

Comments
 (0)