Ignore:
Timestamp:
May 24, 2014, 8:50:43 PM (11 years ago)
Author:
[email protected]
Message:

Object.prototype.toString() should use cached strings for null/undefined.
<https://webkit.org/b/133261>

Normally, when calling Object.prototype.toString() on a regular object,
we'd cache the result of the stringification on the object's structure,
making repeated calls fast.

For null and undefined, we were not as smart. We'd instead construct a
new string with either "[object Null]" or "[object Undefined]" each time.

This was exposed by Dromaeo's JS library tests, where some prototype.js
subtests generate millions of strings this way.

This patch adds two VM-permanent cached strings to the SmallStrings.
Looks like ~10% speed-up on Dromaeo/jslib-traverse-prototype.html

Reviewed by Darin Adler.

  • runtime/ObjectPrototype.cpp:

(JSC::objectProtoFuncToString):

  • runtime/SmallStrings.cpp:

(JSC::SmallStrings::SmallStrings):
(JSC::SmallStrings::initializeCommonStrings):
(JSC::SmallStrings::visitStrongReferences):

  • runtime/SmallStrings.h:

(JSC::SmallStrings::nullObjectString):
(JSC::SmallStrings::undefinedObjectString):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/SmallStrings.h

    r160344 r169316  
    8787#undef JSC_COMMON_STRINGS_ACCESSOR_DEFINITION
    8888
     89        JSString* nullObjectString() const { return m_nullObjectString; }
     90        JSString* undefinedObjectString() const { return m_undefinedObjectString; }
     91
    8992    private:
    9093        static const unsigned singleCharacterStringCount = maxSingleCharacterString + 1;
     
    99102        JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ATTRIBUTE_DECLARATION)
    100103#undef JSC_COMMON_STRINGS_ATTRIBUTE_DECLARATION
     104        JSString* m_nullObjectString;
     105        JSString* m_undefinedObjectString;
    101106        JSString* m_singleCharacterStrings[singleCharacterStringCount];
    102107        OwnPtr<SmallStringsStorage> m_storage;
Note: See TracChangeset for help on using the changeset viewer.