mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1334744 - Add a faster API for working with external strings. r=luke
--HG-- extra : rebase_source : 99b93a6cb0dde0960d1d4349498dd3e61fefec56
This commit is contained in:
parent
7700214282
commit
f75c5acde7
@ -567,6 +567,7 @@ struct String
|
||||
static const uint32_t INLINE_CHARS_BIT = JS_BIT(2);
|
||||
static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6);
|
||||
static const uint32_t ROPE_FLAGS = 0;
|
||||
static const uint32_t EXTERNAL_FLAGS = JS_BIT(5);
|
||||
static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1;
|
||||
uint32_t flags;
|
||||
uint32_t length;
|
||||
@ -576,6 +577,7 @@ struct String
|
||||
JS::Latin1Char inlineStorageLatin1[1];
|
||||
char16_t inlineStorageTwoByte[1];
|
||||
};
|
||||
const JSStringFinalizer* externalFinalizer;
|
||||
};
|
||||
|
||||
} /* namespace shadow */
|
||||
@ -830,6 +832,21 @@ GetTwoByteAtomChars(const JS::AutoCheckCannotGC& nogc, JSAtom* atom)
|
||||
return GetTwoByteLinearStringChars(nogc, AtomToLinearString(atom));
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
IsExternalString(JSString* str, const JSStringFinalizer** fin, const char16_t** chars)
|
||||
{
|
||||
using shadow::String;
|
||||
String* s = reinterpret_cast<String*>(str);
|
||||
|
||||
if ((s->flags & String::TYPE_FLAGS_MASK) != String::EXTERNAL_FLAGS)
|
||||
return false;
|
||||
|
||||
MOZ_ASSERT(JS_IsExternalString(str));
|
||||
*fin = s->externalFinalizer;
|
||||
*chars = s->nonInlineCharsTwoByte;
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSLinearString*)
|
||||
StringToLinearStringSlow(JSContext* cx, JSString* str);
|
||||
|
||||
|
@ -302,6 +302,8 @@ class JSString : public js::gc::TenuredCell
|
||||
"shadow::String nonInlineChars offset must match JSString");
|
||||
static_assert(offsetof(JSString, d.s.u2.nonInlineCharsTwoByte) == offsetof(String, nonInlineCharsTwoByte),
|
||||
"shadow::String nonInlineChars offset must match JSString");
|
||||
static_assert(offsetof(JSString, d.s.u3.externalFinalizer) == offsetof(String, externalFinalizer),
|
||||
"shadow::String externalFinalizer offset must match JSString");
|
||||
static_assert(offsetof(JSString, d.inlineStorageLatin1) == offsetof(String, inlineStorageLatin1),
|
||||
"shadow::String inlineStorage offset must match JSString");
|
||||
static_assert(offsetof(JSString, d.inlineStorageTwoByte) == offsetof(String, inlineStorageTwoByte),
|
||||
@ -314,6 +316,8 @@ class JSString : public js::gc::TenuredCell
|
||||
"shadow::String::TYPE_FLAGS_MASK must match JSString::TYPE_FLAGS_MASK");
|
||||
static_assert(ROPE_FLAGS == String::ROPE_FLAGS,
|
||||
"shadow::String::ROPE_FLAGS must match JSString::ROPE_FLAGS");
|
||||
static_assert(EXTERNAL_FLAGS == String::EXTERNAL_FLAGS,
|
||||
"shadow::String::EXTERNAL_FLAGS must match JSString::EXTERNAL_FLAGS");
|
||||
}
|
||||
|
||||
/* Avoid lame compile errors in JSRope::flatten */
|
||||
|
Loading…
Reference in New Issue
Block a user