Skip to content

Commit 62af4d3

Browse files
committed
src: do not use simdutf path on very short input
1 parent d4f0460 commit 62af4d3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/string_bytes.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,10 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate,
539539
return ExternOneByteString::NewFromCopy(isolate, buf, buflen);
540540
}
541541

542-
if (simdutf::validate_utf8(buf, buflen)) {
542+
if (buflen >= 32 && simdutf::validate_utf8(buf, buflen)) {
543543
// We know that we are non-ASCII (and are unlikely Latin1), use 2-byte
544544
// In the most likely case of valid UTF-8, we can use this fast impl
545+
// For very short input, it is slower, so we limit min size
545546
size_t u16size = simdutf::utf16_length_from_utf8(buf, buflen);
546547
if (u16size > static_cast<size_t>(v8::String::kMaxLength)) {
547548
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));

0 commit comments

Comments
 (0)