Chromium Code Reviews| Index: src/heap.cc |
| diff --git a/src/heap.cc b/src/heap.cc |
| index 2f70ef0188dbad295cb44622708e2dec3c4a4b24..4713f69e2f0e622b9e2ec9db99a28d24ef148ce5 100644 |
| --- a/src/heap.cc |
| +++ b/src/heap.cc |
| @@ -2549,20 +2549,10 @@ MaybeObject* Heap::AllocateExternalStringFromTwoByte( |
| } |
| // For small strings we check whether the resource contains only |
| - // ascii characters. If yes, we use a different string map. |
| - bool is_ascii = true; |
| - if (length >= static_cast<size_t>(String::kMinNonFlatLength)) { |
| - is_ascii = false; |
| - } else { |
| - const uc16* data = resource->data(); |
| - for (size_t i = 0; i < length; i++) { |
| - if (data[i] > String::kMaxAsciiCharCode) { |
| - is_ascii = false; |
| - break; |
| - } |
| - } |
| - } |
| - |
| + // ASCII characters. If yes, we use a different string map. |
| + static const size_t kAsciiCheckLengthLimit = 32; |
| + bool is_ascii = length <= kAsciiCheckLengthLimit && |
| + String::IsAscii(resource->data(), length); |
|
Mads Ager (chromium)
2010/12/22 07:46:24
Four-space indent?
|
| Map* map = is_ascii ? |
| Heap::external_string_with_ascii_data_map() : Heap::external_string_map(); |
| Object* result; |
| @@ -3342,11 +3332,8 @@ MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, |
| MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, |
| PretenureFlag pretenure) { |
| // Check if the string is an ASCII string. |
| - int i = 0; |
| - while (i < string.length() && string[i] <= String::kMaxAsciiCharCode) i++; |
| - |
| MaybeObject* maybe_result; |
| - if (i == string.length()) { // It's an ASCII string. |
| + if (String::IsAscii(string.start(), string.length())) { |
| maybe_result = AllocateRawAsciiString(string.length(), pretenure); |
| } else { // It's not an ASCII string. |
| maybe_result = AllocateRawTwoByteString(string.length(), pretenure); |