| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cb8bc34 commit 0692b4f
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -356,7 +356,24 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo<Value>& args) { | |||
| 356 | 356 | const char* data = buffer.data(); | |
| 357 | 357 | size_t length = buffer.length(); | |
| 358 | 358 | ||
| 359 | + if (!ignore_bom && length >= 3) { | ||
| 360 | + if (memcmp(data, "\xEF\xBB\xBF", 3) == 0) { | ||
| 361 | + data += 3; | ||
| 362 | + length -= 3; | ||
| 363 | + } | ||
| 364 | + } | ||
| 365 | + | ||
| 359 | 366 | if (has_fatal) { | |
| 367 | + // Are we perhaps ASCII? Then we won't have to check for UTF-8 | ||
| 368 | + if (!simdutf::validate_ascii_with_errors(data, length).error) { | ||
| 369 | + Local<Value> ret; | ||
| 370 | + if (StringBytes::Encode(env->isolate(), data, length, LATIN1) | ||
| 371 | + .ToLocal(&ret)) { | ||
| 372 | + args.GetReturnValue().Set(ret); | ||
| 373 | + } | ||
| 374 | + return; | ||
| 375 | + } | ||
| 376 | + | ||
| 360 | 377 | auto result = simdutf::validate_utf8_with_errors(data, length); | |
| 361 | 378 | ||
| 362 | 379 | if (result.error) { | |
@@ -365,13 +382,6 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo<Value>& args) { | |||
| 365 | 382 | } | |
| 366 | 383 | } | |
| 367 | 384 | ||
| 368 | - if (!ignore_bom && length >= 3) { | ||
| 369 | - if (memcmp(data, "\xEF\xBB\xBF", 3) == 0) { | ||
| 370 | - data += 3; | ||
| 371 | - length -= 3; | ||
| 372 | - } | ||
| 373 | - } | ||
| 374 | - | ||
| 375 | 385 | if (length == 0) return args.GetReturnValue().SetEmptyString(); | |
| 376 | 386 | ||
| 377 | 387 | Local<Value> ret; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -531,6 +531,14 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate, | |||
| 531 | 531 | ||
| 532 | 532 | case UTF8: { | |
| 533 | 533 | buflen = keep_buflen_in_range(buflen); | |
| 534 | + | ||
| 535 | + // ASCII fast path | ||
| 536 | + // TODO(chalker): remove when String::NewFromUtf8 is fast enough itself | ||
| 537 | + // This is cheap compared to the benefits though | ||
| 538 | + if (!simdutf::validate_ascii_with_errors(buf, buflen).error) { | ||
| 539 | + return ExternOneByteString::NewFromCopy(isolate, buf, buflen); | ||
| 540 | + } | ||
| 541 | + | ||
| 534 | 542 | val = | |
| 535 | 543 | String::NewFromUtf8(isolate, buf, v8::NewStringType::kNormal, buflen); | |
| 536 | 544 | Local<String> str; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments