File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 3535#include " v8-fast-api-calls.h"
3636#include " v8.h"
3737
38+ #include < bit>
3839#include < climits>
3940#include < cstring>
4041#include " nbytes.h"
@@ -752,12 +753,23 @@ uint32_t FastByteLengthUtf8(Local<Value> receiver,
752753 if (source.length > 128 ) {
753754 return simdutf::utf8_length_from_latin1 (source.data , source.length );
754755 }
756+
755757 uint32_t length = source.length ;
756758 uint32_t result = length;
757759 const uint8_t * data = reinterpret_cast <const uint8_t *>(source.data );
758- for (uint32_t i = 0 ; i < length; ++i) {
760+
761+ uint32_t i = 0 ;
762+ const auto length8 = length & ~0x7 ;
763+ while (i < length8) {
764+ result += std::popcount (*reinterpret_cast <const uint64_t *>(data + i) & 0x8080808080808080 );
765+ i += 8 ;
766+ }
767+
768+ while (i < length) {
759769 result += (data[i] >> 7 );
770+ i++;
760771 }
772+
761773 return result;
762774}
763775
You can’t perform that action at this time.
0 commit comments