mirror of
https://github.com/nodejs/node.git
synced 2026-11-15 10:36:53 -05:00
src: implement FastByteLengthUtf8 with simdutf::utf8_length_from_latin1
PR-URL: https://github.com/nodejs/node/pull/50840 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
This commit is contained in:
1 parent
14e3444a66
commit
891bd5b7d5
2 files changed
+10
-3
No files matched your search
+6
-2
@@ -743,13 +743,17 @@ void SlowByteLengthUtf8(const FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
uint32_t FastByteLengthUtf8(Local<Value> receiver,
|
||||
const v8::FastOneByteString& source) {
|
||||
uint32_t result = 0;
|
||||
// For short inputs, the function call overhead to simdutf is maybe
|
||||
// not worth it, reserve simdutf for long strings.
|
||||
if (source.length > 128) {
|
||||
return simdutf::utf8_length_from_latin1(source.data, source.length);
|
||||
}
|
||||
uint32_t length = source.length;
|
||||
uint32_t result = length;
|
||||
const uint8_t* data = reinterpret_cast<const uint8_t*>(source.data);
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
result += (data[i] >> 7);
|
||||
}
|
||||
result += length;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user