Bug 1041469 part 1 - Remove EnableLatin1Strings flag. r=luke

This commit is contained in:
Jan de Mooij 2014-07-22 14:52:03 +02:00
parent 509bc21287
commit 04d9edfb22
6 changed files with 8 additions and 159 deletions

View File

@ -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>

View File

@ -6408,11 +6408,6 @@ main(int argc, char **argv, char **envp)
#endif // DEBUG
// Set this option before initializing the JSRuntime, so that Latin1 strings
// are used for strings allocated during initialization.
if (op.getBoolOption("latin1-strings"))
js::EnableLatin1Strings = true;
#ifdef JS_THREADSAFE
// The fake thread count must be set before initializing the Runtime,
// which spins up the thread pool.

View File

@ -46,25 +46,12 @@ static MOZ_ALWAYS_INLINE JSInlineString *
NewFatInlineString(ThreadSafeContext *cx, mozilla::Range<const Latin1Char> chars)
{
size_t len = chars.length();
if (EnableLatin1Strings) {
Latin1Char *p;
JSInlineString *str = AllocateFatInlineString<allowGC>(cx, len, &p);
if (!str)
return nullptr;
mozilla::PodCopy(p, chars.start().get(), len);
p[len] = '\0';
return str;
}
jschar *p;
Latin1Char *p;
JSInlineString *str = AllocateFatInlineString<allowGC>(cx, len, &p);
if (!str)
return nullptr;
for (size_t i = 0; i < len; ++i)
p[i] = static_cast<jschar>(chars[i]);
mozilla::PodCopy(p, chars.start().get(), len);
p[len] = '\0';
return str;
}

View File

@ -885,8 +885,6 @@ AutoStableStringChars::initTwoByte(JSContext *cx, JSString *s)
return true;
}
bool js::EnableLatin1Strings = true;
#ifdef DEBUG
void
JSAtom::dump()
@ -924,30 +922,9 @@ js::NewDependentString(JSContext *cx, JSString *baseArg, size_t start, size_t le
return JSDependentString::new_(cx, base, start, length);
}
template <typename CharT>
static void
CopyCharsMaybeInflate(jschar *dest, const CharT *src, size_t len);
template <>
void
CopyCharsMaybeInflate(jschar *dest, const jschar *src, size_t len)
{
PodCopy(dest, src, len);
}
template <>
void
CopyCharsMaybeInflate(jschar *dest, const Latin1Char *src, size_t len)
{
CopyAndInflateChars(dest, src, len);
}
static bool
CanStoreCharsAsLatin1(const jschar *s, size_t length)
{
if (!EnableLatin1Strings)
return false;
for (const jschar *end = s + length; s < end; ++s) {
if (*s > JSString::MAX_LATIN1_CHAR)
return false;
@ -966,8 +943,6 @@ template <AllowGC allowGC>
static MOZ_ALWAYS_INLINE JSInlineString *
NewFatInlineStringDeflated(ThreadSafeContext *cx, mozilla::Range<const jschar> chars)
{
MOZ_ASSERT(EnableLatin1Strings);
size_t len = chars.length();
Latin1Char *storage;
JSInlineString *str = AllocateFatInlineString<allowGC>(cx, len, &storage);
@ -986,8 +961,6 @@ template <AllowGC allowGC>
static JSFlatString *
NewStringDeflated(ThreadSafeContext *cx, const jschar *s, size_t n)
{
MOZ_ASSERT(EnableLatin1Strings);
if (JSFatInlineString::latin1LengthFits(n))
return NewFatInlineStringDeflated<allowGC>(cx, mozilla::Range<const jschar>(s, n));
@ -1088,33 +1061,14 @@ template <AllowGC allowGC, typename CharT>
JSFlatString *
NewStringCopyNDontDeflate(ThreadSafeContext *cx, const CharT *s, size_t n)
{
if (EnableLatin1Strings) {
if (JSFatInlineString::lengthFits<CharT>(n))
return NewFatInlineString<allowGC>(cx, mozilla::Range<const CharT>(s, n));
ScopedJSFreePtr<CharT> news(cx->pod_malloc<CharT>(n + 1));
if (!news)
return nullptr;
PodCopy(news.get(), s, n);
news[n] = 0;
JSFlatString *str = JSFlatString::new_<allowGC>(cx, news.get(), n);
if (!str)
return nullptr;
news.forget();
return str;
}
if (JSFatInlineString::twoByteLengthFits(n))
if (JSFatInlineString::lengthFits<CharT>(n))
return NewFatInlineString<allowGC>(cx, mozilla::Range<const CharT>(s, n));
ScopedJSFreePtr<jschar> news(cx->pod_malloc<jschar>(n + 1));
ScopedJSFreePtr<CharT> news(cx->pod_malloc<CharT>(n + 1));
if (!news)
return nullptr;
CopyCharsMaybeInflate(news.get(), s, n);
PodCopy(news.get(), s, n);
news[n] = 0;
JSFlatString *str = JSFlatString::new_<allowGC>(cx, news.get(), n);

View File

@ -964,9 +964,6 @@ JS_STATIC_ASSERT(sizeof(JSAtom) == sizeof(JSString));
namespace js {
/* Temporary flag to enable Latin1 strings (bug 998392). */
extern bool EnableLatin1Strings;
/*
* Thread safe RAII wrapper for inspecting the contents of JSStrings. The
* thread safe operations such as |getCharsNonDestructive| require allocation

View File

@ -76,10 +76,7 @@ class StringBuffer
explicit StringBuffer(ExclusiveContext *cx)
: cx(cx), hasEnsuredTwoByteChars_(false), reserved_(0)
{
if (EnableLatin1Strings)
cb.construct<Latin1CharBuffer>(cx);
else
cb.construct<TwoByteCharBuffer>(cx);
cb.construct<Latin1CharBuffer>(cx);
}
inline bool reserve(size_t len) {