| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 3330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3341 MaybeObject* Heap::AllocateStringFromAscii(Vector<const char> string, | 3341 MaybeObject* Heap::AllocateStringFromAscii(Vector<const char> string, |
| 3342 PretenureFlag pretenure) { | 3342 PretenureFlag pretenure) { |
| 3343 Object* result; | 3343 Object* result; |
| 3344 { MaybeObject* maybe_result = | 3344 { MaybeObject* maybe_result = |
| 3345 AllocateRawAsciiString(string.length(), pretenure); | 3345 AllocateRawAsciiString(string.length(), pretenure); |
| 3346 if (!maybe_result->ToObject(&result)) return maybe_result; | 3346 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3347 } | 3347 } |
| 3348 | 3348 |
| 3349 // Copy the characters into the new object. | 3349 // Copy the characters into the new object. |
| 3350 SeqAsciiString* string_result = SeqAsciiString::cast(result); | 3350 SeqAsciiString* string_result = SeqAsciiString::cast(result); |
| 3351 for (int i = 0; i < string.length(); i++) { | 3351 int i; |
| 3352 for (i = 0; i < string.length(); i++) { |
| 3352 string_result->SeqAsciiStringSet(i, string[i]); | 3353 string_result->SeqAsciiStringSet(i, string[i]); |
| 3354 if (string[i] == '\0') break; |
| 3353 } | 3355 } |
| 3356 string_result->set_length(i); |
| 3354 return result; | 3357 return result; |
| 3355 } | 3358 } |
| 3356 | 3359 |
| 3357 | 3360 |
| 3358 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, | 3361 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, |
| 3359 PretenureFlag pretenure) { | 3362 PretenureFlag pretenure) { |
| 3360 // V8 only supports characters in the Basic Multilingual Plane. | 3363 // V8 only supports characters in the Basic Multilingual Plane. |
| 3361 const uc32 kMaxSupportedChar = 0xFFFF; | 3364 const uc32 kMaxSupportedChar = 0xFFFF; |
| 3362 // Count the number of characters in the UTF-8 string and check if | 3365 // Count the number of characters in the UTF-8 string and check if |
| 3363 // it is an ASCII string. | 3366 // it is an ASCII string. |
| 3364 Access<ScannerConstants::Utf8Decoder> | 3367 Access<ScannerConstants::Utf8Decoder> |
| 3365 decoder(ScannerConstants::utf8_decoder()); | 3368 decoder(ScannerConstants::utf8_decoder()); |
| 3366 decoder->Reset(string.start(), string.length()); | 3369 decoder->Reset(string.start(), string.length()); |
| 3367 int chars = 0; | 3370 int chars = 0; |
| 3368 while (decoder->has_more()) { | 3371 while (decoder->has_more()) { |
| 3369 decoder->GetNext(); | 3372 decoder->GetNext(); |
| 3370 chars++; | 3373 chars++; |
| 3371 } | 3374 } |
| 3372 | 3375 |
| 3373 Object* result; | 3376 Object* result; |
| 3374 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); | 3377 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); |
| 3375 if (!maybe_result->ToObject(&result)) return maybe_result; | 3378 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3376 } | 3379 } |
| 3377 | 3380 |
| 3378 // Convert and copy the characters into the new object. | 3381 // Convert and copy the characters into the new object. |
| 3379 String* string_result = String::cast(result); | 3382 String* string_result = String::cast(result); |
| 3380 decoder->Reset(string.start(), string.length()); | 3383 decoder->Reset(string.start(), string.length()); |
| 3381 for (int i = 0; i < chars; i++) { | 3384 int i; |
| 3385 for (i = 0; i < chars; i++) { |
| 3382 uc32 r = decoder->GetNext(); | 3386 uc32 r = decoder->GetNext(); |
| 3383 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; } | 3387 if (r > kMaxSupportedChar) { r = unibrow::Utf8::kBadChar; } |
| 3384 string_result->Set(i, r); | 3388 string_result->Set(i, r); |
| 3389 if (r == 0) break; |
| 3385 } | 3390 } |
| 3391 string_result->set_length(i); |
| 3386 return result; | 3392 return result; |
| 3387 } | 3393 } |
| 3388 | 3394 |
| 3389 | 3395 |
| 3390 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, | 3396 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, |
| 3391 PretenureFlag pretenure) { | 3397 PretenureFlag pretenure) { |
| 3392 // Check if the string is an ASCII string. | 3398 // Check if the string is an ASCII string. |
| 3393 MaybeObject* maybe_result; | 3399 MaybeObject* maybe_result; |
| 3394 if (String::IsAscii(string.start(), string.length())) { | 3400 if (String::IsAscii(string.start(), string.length())) { |
| 3395 maybe_result = AllocateRawAsciiString(string.length(), pretenure); | 3401 maybe_result = AllocateRawAsciiString(string.length(), pretenure); |
| (...skipping 2192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5588 void ExternalStringTable::TearDown() { | 5594 void ExternalStringTable::TearDown() { |
| 5589 new_space_strings_.Free(); | 5595 new_space_strings_.Free(); |
| 5590 old_space_strings_.Free(); | 5596 old_space_strings_.Free(); |
| 5591 } | 5597 } |
| 5592 | 5598 |
| 5593 | 5599 |
| 5594 List<Object*> ExternalStringTable::new_space_strings_; | 5600 List<Object*> ExternalStringTable::new_space_strings_; |
| 5595 List<Object*> ExternalStringTable::old_space_strings_; | 5601 List<Object*> ExternalStringTable::old_space_strings_; |
| 5596 | 5602 |
| 5597 } } // namespace v8::internal | 5603 } } // namespace v8::internal |
| OLD | NEW |