Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/V8StringResource.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/V8StringResource.cpp b/third_party/WebKit/Source/bindings/core/v8/V8StringResource.cpp |
| index 5dc1eb2eaaabab6a37058e59000353c2e0f1ab11..0c00845ae5fad66efaabbc7a1aad355e4a7bc7e4 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/V8StringResource.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/V8StringResource.cpp |
| @@ -39,7 +39,7 @@ template<class StringClass> struct StringTraits { |
| template<> |
| struct StringTraits<String> { |
| - static const String& fromStringResource(WebCoreStringResourceBase* resource) |
| + static String fromStringResource(WebCoreStringResourceBase* resource) |
| { |
| return resource->webcoreString(); |
| } |
| @@ -49,7 +49,7 @@ struct StringTraits<String> { |
| template<> |
| struct StringTraits<AtomicString> { |
| - static const AtomicString& fromStringResource(WebCoreStringResourceBase* resource) |
| + static AtomicString fromStringResource(WebCoreStringResourceBase* resource) |
| { |
| return resource->atomicString(); |
| } |
| @@ -108,10 +108,17 @@ StringType v8StringToWebCoreString(v8::Local<v8::String> v8String, ExternalMode |
| v8::String::ExternalStringResourceBase* resource = v8String->GetExternalStringResourceBase(&encoding); |
| if (LIKELY(!!resource)) { |
| WebCoreStringResourceBase* base; |
| - if (encoding == v8::String::ONE_BYTE_ENCODING) |
| - base = static_cast<WebCoreStringResource8*>(resource); |
| - else |
| - base = static_cast<WebCoreStringResource16*>(resource); |
| + if (UNLIKELY(resource->isCompressable())) { |
| + if (encoding == v8::String::ONE_BYTE_ENCODING) |
| + base = static_cast<WebCoreCompressableStringResource8*>(resource); |
| + else |
| + base = static_cast<WebCoreCompressableStringResource16*>(resource); |
| + } else { |
| + if (encoding == v8::String::ONE_BYTE_ENCODING) |
| + base = static_cast<WebCoreStringResource8*>(resource); |
| + else |
| + base = static_cast<WebCoreStringResource16*>(resource); |
| + } |
| return StringTraits<StringType>::fromStringResource(base); |
| } |
| } |
| @@ -143,6 +150,48 @@ StringType v8StringToWebCoreString(v8::Local<v8::String> v8String, ExternalMode |
| template String v8StringToWebCoreString<String>(v8::Local<v8::String>, ExternalMode); |
| template AtomicString v8StringToWebCoreString<AtomicString>(v8::Local<v8::String>, ExternalMode); |
| +template String v8StringToWebCoreString2<String>(v8::Local<v8::String>, ExternalMode); |
|
haraken
2015/11/24 11:15:41
Do we need this template?
hajimehoshi
2015/11/26 10:49:13
Sorry but this was a test code. Removed.
|
| + |
| +template<typename StringType> |
| +StringType v8StringToWebCoreString2(v8::Local<v8::String> v8String, ExternalMode external) |
|
haraken
2015/11/24 11:15:41
Ditto.
hajimehoshi
2015/11/26 10:49:13
Done.
|
| +{ |
| + { |
| + // This portion of this function is very hot in certain Dromeao benchmarks. |
| + v8::String::Encoding encoding; |
| + v8::String::ExternalStringResourceBase* resource = v8String->GetExternalStringResourceBase(&encoding); |
| + if (LIKELY(!!resource)) { |
| + // TODO(hajimehoshi): What if resource is a compressablestring??? |
| + WebCoreStringResourceBase* base; |
| + if (encoding == v8::String::ONE_BYTE_ENCODING) |
| + base = static_cast<WebCoreStringResource8*>(resource); |
| + else |
| + base = static_cast<WebCoreStringResource16*>(resource); |
| + return StringTraits<StringType>::fromStringResource(base); |
| + } |
| + } |
| + |
| + int length = v8String->Length(); |
| + if (UNLIKELY(!length)) |
| + return StringType(""); |
| + |
| + bool oneByte = v8String->ContainsOnlyOneByte(); |
| + StringType result(oneByte ? StringTraits<StringType>::template fromV8String<V8StringOneByteTrait>(v8String, length) : StringTraits<StringType>::template fromV8String<V8StringTwoBytesTrait>(v8String, length)); |
| + |
| + if (external != Externalize || !v8String->CanMakeExternal()) |
| + return result; |
| + |
| + if (result.is8Bit()) { |
| + WebCoreStringResource8* stringResource = new WebCoreStringResource8(result); |
| + if (UNLIKELY(!v8String->MakeExternal(stringResource))) |
| + delete stringResource; |
| + } else { |
| + WebCoreStringResource16* stringResource = new WebCoreStringResource16(result); |
| + if (UNLIKELY(!v8String->MakeExternal(stringResource))) |
| + delete stringResource; |
| + } |
| + return result; |
| +} |
| + |
| // Fast but non thread-safe version. |
| String int32ToWebCoreStringFast(int value) |
| { |