Bug 966264 - Don't allocate new "[object Foo]" strings for the most common classes. r=njn

This commit is contained in:
Jan de Mooij 2014-02-01 13:13:41 +01:00
parent 808b00705b
commit 80f041fdbf
2 changed files with 22 additions and 0 deletions

View File

@ -272,8 +272,24 @@ js::ObjectToSource(JSContext *cx, HandleObject obj)
JSString *
JS_BasicObjectToString(JSContext *cx, HandleObject obj)
{
// Some classes are really common, don't allocate new strings for them.
// The ordering below is based on the measurements in bug 966264.
if (obj->is<JSObject>())
return cx->names().objectObject;
if (obj->is<StringObject>())
return cx->names().objectString;
if (obj->is<ArrayObject>())
return cx->names().objectArray;
if (obj->is<JSFunction>())
return cx->names().objectFunction;
if (obj->is<NumberObject>())
return cx->names().objectNumber;
const char *className = JSObject::className(cx, obj);
if (strcmp(className, "Window") == 0)
return cx->names().objectWindow;
StringBuffer sb(cx);
if (!sb.append("[object ") || !sb.appendInflated(className, strlen(className)) ||
!sb.append("]"))

View File

@ -129,8 +129,14 @@
macro(NumberFormat, NumberFormat, "NumberFormat") \
macro(NumberFormatFormatGet, NumberFormatFormatGet, "Intl_NumberFormat_format_get") \
macro(numeric, numeric, "numeric") \
macro(objectArray, objectArray, "[object Array]") \
macro(objectFunction, objectFunction, "[object Function]") \
macro(objectNull, objectNull, "[object Null]") \
macro(objectNumber, objectNumber, "[object Number]") \
macro(objectObject, objectObject, "[object Object]") \
macro(objectString, objectString, "[object String]") \
macro(objectUndefined, objectUndefined, "[object Undefined]") \
macro(objectWindow, objectWindow, "[object Window]") \
macro(of, of, "of") \
macro(offset, offset, "offset") \
macro(outOfMemory, outOfMemory, "out of memory") \