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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "bindings/v8/V8StringResource.h" | 27 #include "bindings/v8/V8StringResource.h" |
28 | 28 |
29 #include "bindings/v8/V8Binding.h" | 29 #include "bindings/v8/V8Binding.h" |
30 #include "core/inspector/BindingVisitors.h" | 30 #include "core/inspector/BindingVisitors.h" |
31 #include "wtf/MainThread.h" | 31 #include "wtf/MainThread.h" |
32 | 32 |
33 namespace WebCore { | 33 namespace WebCore { |
34 | 34 |
35 WebCoreStringResourceBase* WebCoreStringResourceBase::toWebCoreStringResourceBas
e(v8::Handle<v8::String> string) | |
36 { | |
37 v8::String::Encoding encoding; | |
38 v8::String::ExternalStringResourceBase* resource = string->GetExternalString
ResourceBase(&encoding); | |
39 if (!resource) | |
40 return 0; | |
41 if (encoding == v8::String::ONE_BYTE_ENCODING) | |
42 return static_cast<WebCoreStringResource8*>(resource); | |
43 return static_cast<WebCoreStringResource16*>(resource); | |
44 } | |
45 | |
46 void WebCoreStringResourceBase::visitStrings(ExternalStringVisitor* visitor) | |
47 { | |
48 visitor->visitJSExternalString(m_plainString.impl()); | |
49 if (m_plainString.impl() != m_atomicString.impl() && !m_atomicString.isNull(
)) | |
50 visitor->visitJSExternalString(m_atomicString.impl()); | |
51 } | |
52 | |
53 template<class StringClass> struct StringTraits { | 35 template<class StringClass> struct StringTraits { |
54 static const StringClass& fromStringResource(WebCoreStringResourceBase*); | 36 static const StringClass& fromStringResource(WebCoreStringResourceBase*); |
55 template <typename V8StringTrait> | 37 template <typename V8StringTrait> |
56 static StringClass fromV8String(v8::Handle<v8::String>, int); | 38 static StringClass fromV8String(v8::Handle<v8::String>, int); |
57 }; | 39 }; |
58 | 40 |
59 template<> | 41 template<> |
60 struct StringTraits<String> { | 42 struct StringTraits<String> { |
61 static const String& fromStringResource(WebCoreStringResourceBase* resource) | 43 static const String& fromStringResource(WebCoreStringResourceBase* resource) |
62 { | 44 { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 typename V8StringTrait::CharType* buffer; | 97 typename V8StringTrait::CharType* buffer; |
116 String string = String::createUninitialized(length, buffer); | 98 String string = String::createUninitialized(length, buffer); |
117 V8StringTrait::write(v8String, buffer, length); | 99 V8StringTrait::write(v8String, buffer, length); |
118 return AtomicString(string); | 100 return AtomicString(string); |
119 } | 101 } |
120 | 102 |
121 template<typename StringType> | 103 template<typename StringType> |
122 StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode
external) | 104 StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode
external) |
123 { | 105 { |
124 { | 106 { |
125 // A lot of WebCoreStringResourceBase::toWebCoreStringResourceBase is co
pied here by hand for performance reasons. | |
126 // This portion of this function is very hot in certain Dromeao benchmar
ks. | 107 // This portion of this function is very hot in certain Dromeao benchmar
ks. |
127 v8::String::Encoding encoding; | 108 v8::String::Encoding encoding; |
128 v8::String::ExternalStringResourceBase* resource = v8String->GetExternal
StringResourceBase(&encoding); | 109 v8::String::ExternalStringResourceBase* resource = v8String->GetExternal
StringResourceBase(&encoding); |
129 if (LIKELY(!!resource)) { | 110 if (LIKELY(!!resource)) { |
130 WebCoreStringResourceBase* base; | 111 WebCoreStringResourceBase* base; |
131 if (encoding == v8::String::ONE_BYTE_ENCODING) | 112 if (encoding == v8::String::ONE_BYTE_ENCODING) |
132 base = static_cast<WebCoreStringResource8*>(resource); | 113 base = static_cast<WebCoreStringResource8*>(resource); |
133 else | 114 else |
134 base = static_cast<WebCoreStringResource16*>(resource); | 115 base = static_cast<WebCoreStringResource16*>(resource); |
135 return StringTraits<StringType>::fromStringResource(base); | 116 return StringTraits<StringType>::fromStringResource(base); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 169 |
189 String int32ToWebCoreString(int value) | 170 String int32ToWebCoreString(int value) |
190 { | 171 { |
191 // If we are on the main thread (this should always true for non-workers), c
all the faster one. | 172 // If we are on the main thread (this should always true for non-workers), c
all the faster one. |
192 if (isMainThread()) | 173 if (isMainThread()) |
193 return int32ToWebCoreStringFast(value); | 174 return int32ToWebCoreStringFast(value); |
194 return String::number(value); | 175 return String::number(value); |
195 } | 176 } |
196 | 177 |
197 } // namespace WebCore | 178 } // namespace WebCore |
OLD | NEW |