OLD | NEW |
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 30 matching lines...) Expand all Loading... |
41 static const String& fromStringResource(WebCoreStringResourceBase* resource) | 41 static const String& fromStringResource(WebCoreStringResourceBase* resource) |
42 { | 42 { |
43 return resource->webcoreString(); | 43 return resource->webcoreString(); |
44 } | 44 } |
45 template <typename V8StringTrait> | 45 template <typename V8StringTrait> |
46 static String fromV8String(v8::Local<v8::String>, int); | 46 static String fromV8String(v8::Local<v8::String>, int); |
47 }; | 47 }; |
48 | 48 |
49 template<> | 49 template<> |
50 struct StringTraits<AtomicString> { | 50 struct StringTraits<AtomicString> { |
51 static const AtomicString& fromStringResource(WebCoreStringResourceBase* res
ource) | 51 static AtomicString fromStringResource(WebCoreStringResourceBase* resource) |
52 { | 52 { |
53 return resource->atomicString(); | 53 return resource->atomicString(); |
54 } | 54 } |
55 template <typename V8StringTrait> | 55 template <typename V8StringTrait> |
56 static AtomicString fromV8String(v8::Local<v8::String>, int); | 56 static AtomicString fromV8String(v8::Local<v8::String>, int); |
57 }; | 57 }; |
58 | 58 |
59 struct V8StringTwoBytesTrait { | 59 struct V8StringTwoBytesTrait { |
60 typedef UChar CharType; | 60 typedef UChar CharType; |
61 ALWAYS_INLINE static void write(v8::Local<v8::String> v8String, CharType* bu
ffer, int length) | 61 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 Loading... |
100 | 100 |
101 template<typename StringType> | 101 template<typename StringType> |
102 StringType v8StringToWebCoreString(v8::Local<v8::String> v8String, ExternalMode
external) | 102 StringType v8StringToWebCoreString(v8::Local<v8::String> v8String, ExternalMode
external) |
103 { | 103 { |
104 { | 104 { |
105 // This portion of this function is very hot in certain Dromeao benchmar
ks. | 105 // This portion of this function is very hot in certain Dromeao benchmar
ks. |
106 v8::String::Encoding encoding; | 106 v8::String::Encoding encoding; |
107 v8::String::ExternalStringResourceBase* resource = v8String->GetExternal
StringResourceBase(&encoding); | 107 v8::String::ExternalStringResourceBase* resource = v8String->GetExternal
StringResourceBase(&encoding); |
108 if (LIKELY(!!resource)) { | 108 if (LIKELY(!!resource)) { |
109 WebCoreStringResourceBase* base; | 109 WebCoreStringResourceBase* base; |
110 if (encoding == v8::String::ONE_BYTE_ENCODING) | 110 if (UNLIKELY(resource->IsCompressible())) { |
111 base = static_cast<WebCoreStringResource8*>(resource); | 111 if (encoding == v8::String::ONE_BYTE_ENCODING) |
112 else | 112 base = static_cast<WebCoreCompressibleStringResource8*>(reso
urce); |
113 base = static_cast<WebCoreStringResource16*>(resource); | 113 else |
| 114 base = static_cast<WebCoreCompressibleStringResource16*>(res
ource); |
| 115 } else { |
| 116 if (encoding == v8::String::ONE_BYTE_ENCODING) |
| 117 base = static_cast<WebCoreStringResource8*>(resource); |
| 118 else |
| 119 base = static_cast<WebCoreStringResource16*>(resource); |
| 120 } |
114 return StringTraits<StringType>::fromStringResource(base); | 121 return StringTraits<StringType>::fromStringResource(base); |
115 } | 122 } |
116 } | 123 } |
117 | 124 |
118 int length = v8String->Length(); | 125 int length = v8String->Length(); |
119 if (UNLIKELY(!length)) | 126 if (UNLIKELY(!length)) |
120 return StringType(""); | 127 return StringType(""); |
121 | 128 |
122 bool oneByte = v8String->ContainsOnlyOneByte(); | 129 bool oneByte = v8String->ContainsOnlyOneByte(); |
123 StringType result(oneByte ? StringTraits<StringType>::template fromV8String<
V8StringOneByteTrait>(v8String, length) : StringTraits<StringType>::template fro
mV8String<V8StringTwoBytesTrait>(v8String, length)); | 130 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 Loading... |
168 | 175 |
169 String int32ToWebCoreString(int value) | 176 String int32ToWebCoreString(int value) |
170 { | 177 { |
171 // If we are on the main thread (this should always true for non-workers), c
all the faster one. | 178 // If we are on the main thread (this should always true for non-workers), c
all the faster one. |
172 if (isMainThread()) | 179 if (isMainThread()) |
173 return int32ToWebCoreStringFast(value); | 180 return int32ToWebCoreStringFast(value); |
174 return String::number(value); | 181 return String::number(value); |
175 } | 182 } |
176 | 183 |
177 } // namespace blink | 184 } // namespace blink |
OLD | NEW |