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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 delete stringResource; | 138 delete stringResource; |
139 } else { | 139 } else { |
140 WebCoreStringResource16* stringResource = | 140 WebCoreStringResource16* stringResource = |
141 new WebCoreStringResource16(result); | 141 new WebCoreStringResource16(result); |
142 if (UNLIKELY(!v8String->MakeExternal(stringResource))) | 142 if (UNLIKELY(!v8String->MakeExternal(stringResource))) |
143 delete stringResource; | 143 delete stringResource; |
144 } | 144 } |
145 return result; | 145 return result; |
146 } | 146 } |
147 | 147 |
148 // Explicitly instantiate the above template with the expected parameterizations
, | 148 // Explicitly instantiate the above template with the expected |
149 // to ensure the compiler generates the code; otherwise link errors can result i
n GCC 4.4. | 149 // parameterizations, to ensure the compiler generates the code; otherwise link |
| 150 // errors can result in GCC 4.4. |
150 template String v8StringToWebCoreString<String>(v8::Local<v8::String>, | 151 template String v8StringToWebCoreString<String>(v8::Local<v8::String>, |
151 ExternalMode); | 152 ExternalMode); |
152 template AtomicString v8StringToWebCoreString<AtomicString>( | 153 template AtomicString v8StringToWebCoreString<AtomicString>( |
153 v8::Local<v8::String>, | 154 v8::Local<v8::String>, |
154 ExternalMode); | 155 ExternalMode); |
155 | 156 |
156 // Fast but non thread-safe version. | 157 // Fast but non thread-safe version. |
157 String int32ToWebCoreStringFast(int value) { | 158 String int32ToWebCoreStringFast(int value) { |
158 // Caching of small strings below is not thread safe: newly constructed Atomic
String | 159 // Caching of small strings below is not thread safe: newly constructed |
159 // are not safely published. | 160 // AtomicString are not safely published. |
160 ASSERT(isMainThread()); | 161 ASSERT(isMainThread()); |
161 | 162 |
162 // Most numbers used are <= 100. Even if they aren't used there's very little
cost in using the space. | 163 // Most numbers used are <= 100. Even if they aren't used there's very little |
| 164 // cost in using the space. |
163 const int kLowNumbers = 100; | 165 const int kLowNumbers = 100; |
164 DEFINE_STATIC_LOCAL(Vector<AtomicString>, lowNumbers, (kLowNumbers + 1)); | 166 DEFINE_STATIC_LOCAL(Vector<AtomicString>, lowNumbers, (kLowNumbers + 1)); |
165 String webCoreString; | 167 String webCoreString; |
166 if (0 <= value && value <= kLowNumbers) { | 168 if (0 <= value && value <= kLowNumbers) { |
167 webCoreString = lowNumbers[value]; | 169 webCoreString = lowNumbers[value]; |
168 if (!webCoreString) { | 170 if (!webCoreString) { |
169 AtomicString valueString = AtomicString::number(value); | 171 AtomicString valueString = AtomicString::number(value); |
170 lowNumbers[value] = valueString; | 172 lowNumbers[value] = valueString; |
171 webCoreString = valueString; | 173 webCoreString = valueString; |
172 } | 174 } |
173 } else { | 175 } else { |
174 webCoreString = String::number(value); | 176 webCoreString = String::number(value); |
175 } | 177 } |
176 return webCoreString; | 178 return webCoreString; |
177 } | 179 } |
178 | 180 |
179 String int32ToWebCoreString(int value) { | 181 String int32ToWebCoreString(int value) { |
180 // If we are on the main thread (this should always true for non-workers), cal
l the faster one. | 182 // If we are on the main thread (this should always true for non-workers), |
| 183 // call the faster one. |
181 if (isMainThread()) | 184 if (isMainThread()) |
182 return int32ToWebCoreStringFast(value); | 185 return int32ToWebCoreStringFast(value); |
183 return String::number(value); | 186 return String::number(value); |
184 } | 187 } |
185 | 188 |
186 } // namespace blink | 189 } // namespace blink |
OLD | NEW |