summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-19 22:59:08 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-19 22:59:08 +0000
commit5b2aa4f6a4f0da8643b56edc8a66e56b18cc7ec1 (patch)
treea348f11ed58c13efe46a521d2027a9bdf8ada3bf /webkit
parent3381b5cf273a8d0311230cbc9e72f08484dd9af7 (diff)
downloadchromium_src-5b2aa4f6a4f0da8643b56edc8a66e56b18cc7ec1.zip
chromium_src-5b2aa4f6a4f0da8643b56edc8a66e56b18cc7ec1.tar.gz
chromium_src-5b2aa4f6a4f0da8643b56edc8a66e56b18cc7ec1.tar.bz2
3 Speedups for turning v8 strings into webcore strings
1) Take advantage of new String::createUninitialized() call in webkit. This allows us to have one malloc node per string, without an extra copy of the characters 2) Take advantage of new V8 behavior, to return NULL from GetExternalStringResource() if it hasn't been externalized, speeding up our usage by not requiring us to call isExternal 3) Check if string type is an integer. If it is, don't call into V8 to get string...instead do it in C++, caching previous integer strings less than 100. Also removed unnecessary test for IsEmpty() as the called function also tests for it. Review URL: http://codereview.chromium.org/115517 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16427 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/port/bindings/v8/v8_binding.cpp60
1 files changed, 31 insertions, 29 deletions
diff --git a/webkit/port/bindings/v8/v8_binding.cpp b/webkit/port/bindings/v8/v8_binding.cpp
index 0df0839..831ca74 100644
--- a/webkit/port/bindings/v8/v8_binding.cpp
+++ b/webkit/port/bindings/v8/v8_binding.cpp
@@ -37,11 +37,12 @@ class WebCoreStringResource: public v8::String::ExternalStringResource {
String impl_;
};
+
String v8StringToWebCoreString(
v8::Handle<v8::String> v8_str, bool externalize) {
- if (v8_str->IsExternal()) {
- WebCoreStringResource* str_resource = static_cast<WebCoreStringResource*>(
- v8_str->GetExternalStringResource());
+ WebCoreStringResource* str_resource = static_cast<WebCoreStringResource*>(
+ v8_str->GetExternalStringResource());
+ if (str_resource) {
return str_resource->webcore_string();
}
@@ -49,27 +50,12 @@ String v8StringToWebCoreString(
if (length == 0) {
// Avoid trying to morph empty strings, as they do not have enough room to
// contain the external reference.
- return "";
+ return StringImpl::empty();
}
- // Copy the characters from the v8::String into a WebCore::String and allocate
- // an external resource which will be attached to the v8::String.
- String result;
- const int kStringSizeToCopy = 256;
- if (length < kStringSizeToCopy) {
- uint16_t buffer[kStringSizeToCopy];
- v8_str->Write(buffer, 0, length);
- result = StringImpl::create(reinterpret_cast<UChar*>(buffer), length);
- } else {
- StringBuffer buf(length);
- v8_str->Write(reinterpret_cast<uint16_t*>(buf.characters()), 0, length);
- result = String::adopt(buf);
- }
-
-//
-// TODO(mbelshe): Disable string morphing because it causes mystery
-// perf regressions on intl1 and intl2 page cyclers. It works fine
-// on machines other than the buildbots.
+ UChar* buffer;
+ String result = String::createUninitialized(length, buffer);
+ v8_str->Write(reinterpret_cast<uint16_t*>(buffer), 0, length);
if (externalize) {
WebCoreStringResource* resource = new WebCoreStringResource(result);
@@ -83,17 +69,33 @@ String v8StringToWebCoreString(
String v8ValueToWebCoreString(v8::Handle<v8::Value> obj) {
- v8::Handle<v8::String> v8_str;
if (obj->IsString()) {
- v8_str = v8::Handle<v8::String>::Cast(obj);
- return v8StringToWebCoreString(v8_str, true);
+ v8::Handle<v8::String> v8_str = v8::Handle<v8::String>::Cast(obj);
+ String webCoreString = v8StringToWebCoreString(v8_str, true);
+ return webCoreString;
+ } else if (obj->IsInt32()) {
+ int value = obj->Int32Value();
+ // Most numbers used are <= 100. Even if they aren't used
+ // there's very little in using the space.
+ const int kLowNumbers = 100;
+ static AtomicString lowNumbers[kLowNumbers + 1];
+ String webCoreString;
+ if (0 <= value && value <= kLowNumbers) {
+ webCoreString = lowNumbers[value];
+ if (!webCoreString) {
+ AtomicString valueString = AtomicString(String::number(value));
+ lowNumbers[value] = valueString;
+ webCoreString = valueString;
+ }
+ } else {
+ webCoreString = String::number(value);
+ }
+ return webCoreString;
} else {
v8::TryCatch block;
- v8_str = obj->ToString();
- if (v8_str.IsEmpty())
- return "";
+ v8::Handle<v8::String> v8_str = obj->ToString();
+ return v8StringToWebCoreString(v8_str, false);
}
- return v8StringToWebCoreString(v8_str, false);
}