Title: [115151] trunk/Source/_javascript_Core
- Revision
- 115151
- Author
- msab...@apple.com
- Date
- 2012-04-24 17:58:17 -0700 (Tue, 24 Apr 2012)
Log Message
objectProtoFuncToString creates new string every invocation
https://bugs.webkit.org/show_bug.cgi?id=84781
Reviewed by Geoffrey Garen.
Cache the results of object toString() in the attached Structure.
* runtime/ObjectPrototype.cpp:
(JSC::objectProtoFuncToString):
* runtime/Structure.cpp:
(JSC::Structure::visitChildren): visit new m_hasObjectToStringValue.
* runtime/Structure.h: Added new member m_hasObjectToStringValue
(JSC):
(JSC::Structure::objectToStringValue):
(Structure):
(JSC::Structure::setObjectToStringValue):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (115150 => 115151)
--- trunk/Source/_javascript_Core/ChangeLog 2012-04-25 00:49:05 UTC (rev 115150)
+++ trunk/Source/_javascript_Core/ChangeLog 2012-04-25 00:58:17 UTC (rev 115151)
@@ -1,3 +1,22 @@
+2012-04-24 Michael Saboff <msab...@apple.com>
+
+ objectProtoFuncToString creates new string every invocation
+ https://bugs.webkit.org/show_bug.cgi?id=84781
+
+ Reviewed by Geoffrey Garen.
+
+ Cache the results of object toString() in the attached Structure.
+
+ * runtime/ObjectPrototype.cpp:
+ (JSC::objectProtoFuncToString):
+ * runtime/Structure.cpp:
+ (JSC::Structure::visitChildren): visit new m_hasObjectToStringValue.
+ * runtime/Structure.h: Added new member m_hasObjectToStringValue
+ (JSC):
+ (JSC::Structure::objectToStringValue):
+ (Structure):
+ (JSC::Structure::setObjectToStringValue):
+
2012-04-24 Thouraya ANDOLSI <thouraya.ando...@st.com>
Reviewed by Oliver Hunt.
Modified: trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp (115150 => 115151)
--- trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp 2012-04-25 00:49:05 UTC (rev 115150)
+++ trunk/Source/_javascript_Core/runtime/ObjectPrototype.cpp 2012-04-25 00:58:17 UTC (rev 115151)
@@ -255,7 +255,17 @@
if (thisValue.isUndefinedOrNull())
return JSValue::encode(jsNontrivialString(exec, thisValue.isUndefined() ? "[object Undefined]" : "[object Null]"));
JSObject* thisObject = thisValue.toObject(exec);
- return JSValue::encode(jsMakeNontrivialString(exec, "[object ", thisObject->methodTable()->className(thisObject), "]"));
+
+ JSString* result = thisObject->structure()->objectToStringValue();
+ if (!result) {
+ RefPtr<StringImpl> newString = WTF::tryMakeString("[object ", thisObject->methodTable()->className(thisObject), "]");
+ if (!newString)
+ return JSValue::encode(throwOutOfMemoryError(exec));
+
+ result = jsNontrivialString(exec, newString.release());
+ thisObject->structure()->setObjectToStringValue(exec->globalData(), thisObject, result);
+ }
+ return JSValue::encode(result);
}
} // namespace JSC
Modified: trunk/Source/_javascript_Core/runtime/Structure.cpp (115150 => 115151)
--- trunk/Source/_javascript_Core/runtime/Structure.cpp 2012-04-25 00:49:05 UTC (rev 115150)
+++ trunk/Source/_javascript_Core/runtime/Structure.cpp 2012-04-25 00:58:17 UTC (rev 115151)
@@ -794,6 +794,8 @@
visitor.append(&ptr->specificValue);
}
}
+ if (thisObject->m_objectToStringValue)
+ visitor.append(&thisObject->m_objectToStringValue);
}
#if DO_PROPERTYMAP_CONSTENCY_CHECK
Modified: trunk/Source/_javascript_Core/runtime/Structure.h (115150 => 115151)
--- trunk/Source/_javascript_Core/runtime/Structure.h 2012-04-25 00:49:05 UTC (rev 115150)
+++ trunk/Source/_javascript_Core/runtime/Structure.h 2012-04-25 00:58:17 UTC (rev 115151)
@@ -50,6 +50,7 @@
class PropertyNameArrayData;
class StructureChain;
class SlotVisitor;
+ class JSString;
class Structure : public JSCell {
public:
@@ -171,6 +172,13 @@
JSPropertyNameIterator* enumerationCache(); // Defined in JSPropertyNameIterator.h.
void getPropertyNamesFromStructure(JSGlobalData&, PropertyNameArray&, EnumerationMode);
+ JSString* objectToStringValue() { return m_objectToStringValue.get(); }
+
+ void setObjectToStringValue(JSGlobalData& globalData, const JSCell* owner, JSString* value)
+ {
+ m_objectToStringValue.set(globalData, owner, value);
+ }
+
bool staticFunctionsReified()
{
return m_staticFunctionReified;
@@ -291,6 +299,8 @@
uint32_t m_propertyStorageCapacity;
+ WriteBarrier<JSString> m_objectToStringValue;
+
// m_offset does not account for anonymous slots
int m_offset;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes