Bug 657537: clean up jschar inflation/deflation. (r=Waldo)

This commit is contained in:
Chris Leary
2011-05-26 15:50:05 -07:00
parent 393685c535
commit 87986934ea
20 changed files with 188 additions and 189 deletions

View File

@@ -546,7 +546,7 @@ js_AtomizeString(JSContext *cx, JSString *str, InternBehavior ib)
}
JSAtom *
js_Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib, bool useCESU8)
js_Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib, FlationCoding fc)
{
CHECK_REQUEST(cx);
@@ -554,7 +554,7 @@ js_Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib, b
return NULL;
/*
* Avoiding the malloc in js_InflateString on shorter strings saves us
* 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
@@ -567,15 +567,15 @@ js_Atomize(JSContext *cx, const char *bytes, size_t length, InternBehavior ib, b
const jschar *chars;
OwnCharsBehavior ocb = CopyChars;
if (length < ATOMIZE_BUF_MAX) {
if (useCESU8)
js_InflateUTF8StringToBuffer(cx, bytes, length, inflated, &inflatedLength, true);
if (fc == CESU8Encoding)
InflateUTF8StringToBuffer(cx, bytes, length, inflated, &inflatedLength, fc);
else
js_InflateStringToBuffer(cx, bytes, length, inflated, &inflatedLength);
InflateStringToBuffer(cx, bytes, length, inflated, &inflatedLength);
inflated[inflatedLength] = 0;
chars = inflated;
} else {
inflatedLength = length;
chars = js_InflateString(cx, bytes, &inflatedLength, useCESU8);
chars = InflateString(cx, bytes, &inflatedLength, fc);
if (!chars)
return NULL;
ocb = TakeCharOwnership;