diff options
author | 2022-02-03 01:01:27 -0800 | |
---|---|---|
committer | 2022-02-03 01:01:27 -0800 | |
commit | b2a69a35b8887c233c606e9f2e7ebec35f82a65e (patch) | |
tree | 00c07f81b2d696252b69db0df40bc40278fbc2c8 /src/javascript/jsc/bindings/helpers.h | |
parent | a52a948a706724895979604e780a6a5d5db92f95 (diff) | |
download | bun-b2a69a35b8887c233c606e9f2e7ebec35f82a65e.tar.gz bun-b2a69a35b8887c233c606e9f2e7ebec35f82a65e.tar.zst bun-b2a69a35b8887c233c606e9f2e7ebec35f82a65e.zip |
Slight improvement to non-ascii file path handling
Diffstat (limited to 'src/javascript/jsc/bindings/helpers.h')
-rw-r--r-- | src/javascript/jsc/bindings/helpers.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/javascript/jsc/bindings/helpers.h b/src/javascript/jsc/bindings/helpers.h index 751ff0f3c..f11aaf064 100644 --- a/src/javascript/jsc/bindings/helpers.h +++ b/src/javascript/jsc/bindings/helpers.h @@ -73,7 +73,8 @@ namespace Zig { static const unsigned char *untag(const unsigned char *ptr) { return reinterpret_cast<const unsigned char *>( ((reinterpret_cast<uintptr_t>(ptr) & ~(static_cast<uint64_t>(1) << 63) & - ~(static_cast<uint64_t>(1) << 62)))); + ~(static_cast<uint64_t>(1) << 62)) & + ~(static_cast<uint64_t>(1) << 61))); } static const JSC::Identifier toIdentifier(ZigString str, JSC::JSGlobalObject *global) { @@ -86,12 +87,18 @@ static bool isTaggedUTF16Ptr(const unsigned char *ptr) { return (reinterpret_cast<uintptr_t>(ptr) & (static_cast<uint64_t>(1) << 63)) != 0; } +// Do we need to upcase the string? +static bool isTaggedUTF8Ptr(const unsigned char *ptr) { + return (reinterpret_cast<uintptr_t>(ptr) & (static_cast<uint64_t>(1) << 61)) != 0; +} + static bool isTaggedExternalPtr(const unsigned char *ptr) { return (reinterpret_cast<uintptr_t>(ptr) & (static_cast<uint64_t>(1) << 62)) != 0; } static const WTF::String toString(ZigString str) { if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); } + if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) { return WTF::String::fromUTF8(untag(str.ptr), str.len); } return !isTaggedUTF16Ptr(str.ptr) ? WTF::String(WTF::StringImpl::createWithoutCopying(untag(str.ptr), str.len)) @@ -101,6 +108,7 @@ static const WTF::String toString(ZigString str) { static const WTF::String toStringCopy(ZigString str) { if (str.len == 0 || str.ptr == nullptr) { return WTF::String(); } + if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) { return WTF::String::fromUTF8(untag(str.ptr), str.len); } return !isTaggedUTF16Ptr(str.ptr) ? WTF::String(WTF::StringImpl::create(untag(str.ptr), str.len)) : WTF::String(WTF::StringImpl::create( |