Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8StringResource.cpp

Issue 1389383003: WIP: Introduce CompressibleString Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: haraken's review Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 21 matching lines...) Expand all
32 namespace blink { 32 namespace blink {
33 33
34 template<class StringClass> struct StringTraits { 34 template<class StringClass> struct StringTraits {
35 static const StringClass& fromStringResource(WebCoreStringResourceBase*); 35 static const StringClass& fromStringResource(WebCoreStringResourceBase*);
36 template <typename V8StringTrait> 36 template <typename V8StringTrait>
37 static StringClass fromV8String(v8::Local<v8::String>, int); 37 static StringClass fromV8String(v8::Local<v8::String>, int);
38 }; 38 };
39 39
40 template<> 40 template<>
41 struct StringTraits<String> { 41 struct StringTraits<String> {
42 static const String& fromStringResource(WebCoreStringResourceBase* resource) 42 static String fromStringResource(WebCoreStringResourceBase* resource)
43 { 43 {
44 return resource->webcoreString(); 44 return resource->webcoreString();
45 } 45 }
46 template <typename V8StringTrait> 46 template <typename V8StringTrait>
47 static String fromV8String(v8::Local<v8::String>, int); 47 static String fromV8String(v8::Local<v8::String>, int);
48 }; 48 };
49 49
50 template<> 50 template<>
51 struct StringTraits<AtomicString> { 51 struct StringTraits<AtomicString> {
52 static const AtomicString& fromStringResource(WebCoreStringResourceBase* res ource) 52 static AtomicString fromStringResource(WebCoreStringResourceBase* resource)
53 { 53 {
54 return resource->atomicString(); 54 return resource->atomicString();
55 } 55 }
56 template <typename V8StringTrait> 56 template <typename V8StringTrait>
57 static AtomicString fromV8String(v8::Local<v8::String>, int); 57 static AtomicString fromV8String(v8::Local<v8::String>, int);
58 }; 58 };
59 59
60 struct V8StringTwoBytesTrait { 60 struct V8StringTwoBytesTrait {
61 typedef UChar CharType; 61 typedef UChar CharType;
62 ALWAYS_INLINE static void write(v8::Local<v8::String> v8String, CharType* bu ffer, int length) 62 ALWAYS_INLINE static void write(v8::Local<v8::String> v8String, CharType* bu ffer, int length)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 template<typename StringType> 102 template<typename StringType>
103 StringType v8StringToWebCoreString(v8::Local<v8::String> v8String, ExternalMode external) 103 StringType v8StringToWebCoreString(v8::Local<v8::String> v8String, ExternalMode external)
104 { 104 {
105 { 105 {
106 // This portion of this function is very hot in certain Dromeao benchmar ks. 106 // This portion of this function is very hot in certain Dromeao benchmar ks.
107 v8::String::Encoding encoding; 107 v8::String::Encoding encoding;
108 v8::String::ExternalStringResourceBase* resource = v8String->GetExternal StringResourceBase(&encoding); 108 v8::String::ExternalStringResourceBase* resource = v8String->GetExternal StringResourceBase(&encoding);
109 if (LIKELY(!!resource)) { 109 if (LIKELY(!!resource)) {
110 WebCoreStringResourceBase* base; 110 WebCoreStringResourceBase* base;
111 if (encoding == v8::String::ONE_BYTE_ENCODING) 111 if (UNLIKELY(resource->isCompressible())) {
112 base = static_cast<WebCoreStringResource8*>(resource); 112 if (encoding == v8::String::ONE_BYTE_ENCODING)
113 else 113 base = static_cast<WebCoreCompressibleStringResource8*>(reso urce);
114 base = static_cast<WebCoreStringResource16*>(resource); 114 else
115 base = static_cast<WebCoreCompressibleStringResource16*>(res ource);
116 } else {
117 if (encoding == v8::String::ONE_BYTE_ENCODING)
118 base = static_cast<WebCoreStringResource8*>(resource);
119 else
120 base = static_cast<WebCoreStringResource16*>(resource);
121 }
115 return StringTraits<StringType>::fromStringResource(base); 122 return StringTraits<StringType>::fromStringResource(base);
116 } 123 }
117 } 124 }
118 125
119 int length = v8String->Length(); 126 int length = v8String->Length();
120 if (UNLIKELY(!length)) 127 if (UNLIKELY(!length))
121 return StringType(""); 128 return StringType("");
122 129
123 bool oneByte = v8String->ContainsOnlyOneByte(); 130 bool oneByte = v8String->ContainsOnlyOneByte();
124 StringType result(oneByte ? StringTraits<StringType>::template fromV8String< V8StringOneByteTrait>(v8String, length) : StringTraits<StringType>::template fro mV8String<V8StringTwoBytesTrait>(v8String, length)); 131 StringType result(oneByte ? StringTraits<StringType>::template fromV8String< V8StringOneByteTrait>(v8String, length) : StringTraits<StringType>::template fro mV8String<V8StringTwoBytesTrait>(v8String, length));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 176
170 String int32ToWebCoreString(int value) 177 String int32ToWebCoreString(int value)
171 { 178 {
172 // If we are on the main thread (this should always true for non-workers), c all the faster one. 179 // If we are on the main thread (this should always true for non-workers), c all the faster one.
173 if (isMainThread()) 180 if (isMainThread())
174 return int32ToWebCoreStringFast(value); 181 return int32ToWebCoreStringFast(value);
175 return String::number(value); 182 return String::number(value);
176 } 183 }
177 184
178 } // namespace blink 185 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698