Bug 1041469 part 1 - Remove EnableLatin1Strings flag. r=luke
This commit is contained in:
@@ -320,66 +320,6 @@ AtomIsInterned(JSContext *cx, JSAtom *atom)
|
||||
return p->isTagged();
|
||||
}
|
||||
|
||||
/*
|
||||
* When the jschars reside in a freshly allocated buffer the memory can be used
|
||||
* as a new JSAtom's storage without copying. The contract is that the caller no
|
||||
* longer owns the memory and this method is responsible for freeing the memory.
|
||||
*/
|
||||
MOZ_ALWAYS_INLINE
|
||||
static JSAtom *
|
||||
AtomizeAndtake(ExclusiveContext *cx, jschar *tbchars, size_t length, InternBehavior ib)
|
||||
{
|
||||
JS_ASSERT(tbchars[length] == 0);
|
||||
|
||||
if (JSAtom *s = cx->staticStrings().lookup(tbchars, length)) {
|
||||
js_free(tbchars);
|
||||
return s;
|
||||
}
|
||||
|
||||
AtomHasher::Lookup lookup(tbchars, length);
|
||||
|
||||
AtomSet::Ptr pp = cx->permanentAtoms().readonlyThreadsafeLookup(lookup);
|
||||
if (pp) {
|
||||
js_free(tbchars);
|
||||
return pp->asPtr();
|
||||
}
|
||||
|
||||
AutoLockForExclusiveAccess lock(cx);
|
||||
|
||||
/*
|
||||
* If a GC occurs at NewStringCopy then |p| will still have the correct
|
||||
* hash, allowing us to avoid rehashing it. Even though the hash is
|
||||
* unchanged, we need to re-lookup the table position because a last-ditch
|
||||
* GC will potentially free some table entries.
|
||||
*/
|
||||
AtomSet& atoms = cx->atoms();
|
||||
AtomSet::AddPtr p = atoms.lookupForAdd(lookup);
|
||||
if (p) {
|
||||
JSAtom *atom = p->asPtr();
|
||||
p->setTagged(bool(ib));
|
||||
js_free(tbchars);
|
||||
return atom;
|
||||
}
|
||||
|
||||
AutoCompartment ac(cx, cx->atomsCompartment());
|
||||
|
||||
JSFlatString *flat = NewString<NoGC>(cx, tbchars, length);
|
||||
if (!flat) {
|
||||
js_free(tbchars);
|
||||
js_ReportOutOfMemory(cx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSAtom *atom = flat->morphAtomizedStringIntoAtom();
|
||||
|
||||
if (!atoms.relookupOrAdd(p, lookup, AtomStateEntry(atom, bool(ib)))) {
|
||||
js_ReportOutOfMemory(cx); /* SystemAllocPolicy does not report OOM. */
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return atom;
|
||||
}
|
||||
|
||||
/* |tbchars| must not point into an inline or short string. */
|
||||
template <typename CharT>
|
||||
MOZ_ALWAYS_INLINE
|
||||
@@ -496,29 +436,8 @@ js::Atomize(ExclusiveContext *cx, const char *bytes, size_t length, InternBehavi
|
||||
if (!JSString::validateLength(cx, length))
|
||||
return nullptr;
|
||||
|
||||
if (EnableLatin1Strings) {
|
||||
const Latin1Char *chars = reinterpret_cast<const Latin1Char*>(bytes);
|
||||
return AtomizeAndCopyChars(cx, chars, length, ib);
|
||||
}
|
||||
|
||||
static const unsigned ATOMIZE_BUF_MAX = 32;
|
||||
if (length < ATOMIZE_BUF_MAX) {
|
||||
/*
|
||||
* Avoiding the malloc in InflateString on shorter strings saves us
|
||||
* 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.
|
||||
*/
|
||||
jschar inflated[ATOMIZE_BUF_MAX];
|
||||
CopyAndInflateChars(inflated, bytes, length);
|
||||
return AtomizeAndCopyChars(cx, inflated, length, ib);
|
||||
}
|
||||
|
||||
jschar *tbcharsZ = InflateString(cx, bytes, &length);
|
||||
if (!tbcharsZ)
|
||||
return nullptr;
|
||||
return AtomizeAndtake(cx, tbcharsZ, length, ib);
|
||||
const Latin1Char *chars = reinterpret_cast<const Latin1Char*>(bytes);
|
||||
return AtomizeAndCopyChars(cx, chars, length, ib);
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
|
||||
Reference in New Issue
Block a user