Object.prototype.toString() should use cached strings for null/undefined.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 May 2014 03:50:43 +0000 (03:50 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 May 2014 03:50:43 +0000 (03:50 +0000)
commitfc03769fc41207e89f0e961ad76d1ecf9f10d3a8
treef8c2bee08918f39a1202cf8c2b50c3b9d377edd8
parentf73bfbbfbe075ea98060e640e8f5e754f38de99c
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@169316 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/ObjectPrototype.cpp
Source/JavaScriptCore/runtime/SmallStrings.cpp
Source/JavaScriptCore/runtime/SmallStrings.h