Bug 780309 - Move atom methods into js namespace; r=luke
This is a simple cleanup of jsatom.h.
This commit is contained in:
@@ -149,7 +149,7 @@ const char js_setter_str[] = "setter";
|
||||
#define JS_STRING_HASH_COUNT 1024
|
||||
|
||||
JSBool
|
||||
js_InitAtomState(JSRuntime *rt)
|
||||
js::InitAtomState(JSRuntime *rt)
|
||||
{
|
||||
JSAtomState *state = &rt->atomState;
|
||||
|
||||
@@ -162,7 +162,7 @@ js_InitAtomState(JSRuntime *rt)
|
||||
}
|
||||
|
||||
void
|
||||
js_FinishAtomState(JSRuntime *rt)
|
||||
js::FinishAtomState(JSRuntime *rt)
|
||||
{
|
||||
JSAtomState *state = &rt->atomState;
|
||||
|
||||
@@ -185,8 +185,8 @@ js::InitCommonAtoms(JSContext *cx)
|
||||
JSAtomState *state = &cx->runtime->atomState;
|
||||
JSAtom **atoms = state->commonAtomsStart();
|
||||
for (size_t i = 0; i < ArrayLength(js_common_atom_names); i++, atoms++) {
|
||||
JSAtom *atom = js_Atomize(cx, js_common_atom_names[i], strlen(js_common_atom_names[i]),
|
||||
InternAtom);
|
||||
JSAtom *atom = Atomize(cx, js_common_atom_names[i], strlen(js_common_atom_names[i]),
|
||||
InternAtom);
|
||||
if (!atom)
|
||||
return false;
|
||||
*atoms = atom->asPropertyName();
|
||||
@@ -327,15 +327,8 @@ AtomizeInline(JSContext *cx, const jschar **pchars, size_t length,
|
||||
return key->morphAtomizedStringIntoAtom();
|
||||
}
|
||||
|
||||
static JSAtom *
|
||||
Atomize(JSContext *cx, const jschar **pchars, size_t length,
|
||||
InternBehavior ib, OwnCharsBehavior ocb = CopyChars)
|
||||
{
|
||||
return AtomizeInline(cx, pchars, length, ib, ocb);
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_AtomizeString(JSContext *cx, JSString *str, InternBehavior ib)
|
||||
js::AtomizeString(JSContext *cx, JSString *str, InternBehavior ib)
|
||||
{
|
||||
if (str->isAtom()) {
|
||||
JSAtom &atom = str->asAtom();
|
||||
@@ -358,11 +351,11 @@ js_AtomizeString(JSContext *cx, JSString *str, InternBehavior ib)
|
||||
return NULL;
|
||||
|
||||
JS_ASSERT(length <= JSString::MAX_LENGTH);
|
||||
return Atomize(cx, &chars, length, ib);
|
||||
return AtomizeInline(cx, &chars, length, ib);
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib, FlationCoding fc)
|
||||
js::Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib, FlationCoding fc)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
|
||||
@@ -374,7 +367,7 @@ js_Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib, F
|
||||
* over 20,000 malloc calls on mozilla browser startup. This compares to
|
||||
* only 131 calls where the string is longer than a 31 char (net) buffer.
|
||||
* The vast majority of atomized strings are already in the hashtable. So
|
||||
* js_AtomizeString rarely has to copy the temp string we make.
|
||||
* js::AtomizeString rarely has to copy the temp string we make.
|
||||
*/
|
||||
static const unsigned ATOMIZE_BUF_MAX = 32;
|
||||
jschar inflated[ATOMIZE_BUF_MAX];
|
||||
@@ -397,14 +390,14 @@ js_Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib, F
|
||||
ocb = TakeCharOwnership;
|
||||
}
|
||||
|
||||
JSAtom *atom = Atomize(cx, &chars, inflatedLength, ib, ocb);
|
||||
JSAtom *atom = AtomizeInline(cx, &chars, inflatedLength, ib, ocb);
|
||||
if (ocb == TakeCharOwnership && chars)
|
||||
cx->free_((void *)chars);
|
||||
return atom;
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, InternBehavior ib)
|
||||
js::AtomizeChars(JSContext *cx, const jschar *chars, size_t length, InternBehavior ib)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
|
||||
@@ -414,37 +407,6 @@ js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, InternBehavio
|
||||
return AtomizeInline(cx, &chars, length, ib);
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_GetExistingStringAtom(JSContext *cx, const jschar *chars, size_t length)
|
||||
{
|
||||
if (JSAtom *atom = cx->runtime->staticStrings.lookup(chars, length))
|
||||
return atom;
|
||||
if (AtomSet::Ptr p = cx->runtime->atomState.atoms.lookup(AtomHasher::Lookup(chars, length)))
|
||||
return p->asPtr();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
JS_FRIEND_API(void)
|
||||
js_DumpAtoms(JSContext *cx, FILE *fp)
|
||||
{
|
||||
JSAtomState *state = &cx->runtime->atomState;
|
||||
|
||||
fprintf(fp, "atoms table contents:\n");
|
||||
unsigned number = 0;
|
||||
for (AtomSet::Range r = state->atoms.all(); !r.empty(); r.popFront()) {
|
||||
AtomStateEntry entry = r.front();
|
||||
fprintf(fp, "%3u ", number++);
|
||||
JSAtom *key = entry.asPtr();
|
||||
FileEscapedString(fp, key, '"');
|
||||
if (entry.isTagged())
|
||||
fputs(" interned", fp);
|
||||
putc('\n', fp);
|
||||
}
|
||||
putc('\n', fp);
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace js {
|
||||
|
||||
bool
|
||||
@@ -456,7 +418,7 @@ IndexToIdSlow(JSContext *cx, uint32_t index, jsid *idp)
|
||||
RangedPtr<jschar> end(ArrayEnd(buf), buf, ArrayEnd(buf));
|
||||
RangedPtr<jschar> start = BackfillIndexInCharBuffer(index, end);
|
||||
|
||||
JSAtom *atom = js_AtomizeChars(cx, start.get(), end - start);
|
||||
JSAtom *atom = AtomizeChars(cx, start.get(), end - start);
|
||||
if (!atom)
|
||||
return false;
|
||||
|
||||
@@ -464,9 +426,11 @@ IndexToIdSlow(JSContext *cx, uint32_t index, jsid *idp)
|
||||
return true;
|
||||
}
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
bool
|
||||
InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval,
|
||||
jsid *idp, MutableHandleValue vp)
|
||||
js::InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval,
|
||||
jsid *idp, MutableHandleValue vp)
|
||||
{
|
||||
#if JS_HAS_XML_SUPPORT
|
||||
if (idval.isObject()) {
|
||||
@@ -500,8 +464,6 @@ InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval,
|
||||
return true;
|
||||
}
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
template<XDRMode mode>
|
||||
bool
|
||||
js::XDRAtom(XDRState<mode> *xdr, JSAtom **atomp)
|
||||
@@ -528,7 +490,7 @@ js::XDRAtom(XDRState<mode> *xdr, JSAtom **atomp)
|
||||
#if IS_LITTLE_ENDIAN
|
||||
/* Directly access the little endian chars in the XDR buffer. */
|
||||
const jschar *chars = reinterpret_cast<const jschar *>(xdr->buf.read(nchars * sizeof(jschar)));
|
||||
atom = js_AtomizeChars(cx, chars, nchars);
|
||||
atom = AtomizeChars(cx, chars, nchars);
|
||||
#else
|
||||
/*
|
||||
* We must copy chars to a temporary buffer to convert between little and
|
||||
@@ -550,7 +512,7 @@ js::XDRAtom(XDRState<mode> *xdr, JSAtom **atomp)
|
||||
}
|
||||
|
||||
JS_ALWAYS_TRUE(xdr->codeChars(chars, nchars));
|
||||
atom = js_AtomizeChars(cx, chars, nchars);
|
||||
atom = AtomizeChars(cx, chars, nchars);
|
||||
if (chars != stackChars)
|
||||
Foreground::free_(chars);
|
||||
#endif /* !IS_LITTLE_ENDIAN */
|
||||
|
||||
Reference in New Issue
Block a user