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 3289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3300 | 3300 |
3301 // Copy the characters into the new object. | 3301 // Copy the characters into the new object. |
3302 SeqAsciiString* string_result = SeqAsciiString::cast(result); | 3302 SeqAsciiString* string_result = SeqAsciiString::cast(result); |
3303 for (int i = 0; i < string.length(); i++) { | 3303 for (int i = 0; i < string.length(); i++) { |
3304 string_result->SeqAsciiStringSet(i, string[i]); | 3304 string_result->SeqAsciiStringSet(i, string[i]); |
3305 } | 3305 } |
3306 return result; | 3306 return result; |
3307 } | 3307 } |
3308 | 3308 |
3309 | 3309 |
3310 MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> string, | 3310 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, |
3311 PretenureFlag pretenure) { | 3311 PretenureFlag pretenure) { |
3312 // V8 only supports characters in the Basic Multilingual Plane. | 3312 // V8 only supports characters in the Basic Multilingual Plane. |
3313 const uc32 kMaxSupportedChar = 0xFFFF; | 3313 const uc32 kMaxSupportedChar = 0xFFFF; |
3314 // Count the number of characters in the UTF-8 string and check if | 3314 // Count the number of characters in the UTF-8 string and check if |
3315 // it is an ASCII string. | 3315 // it is an ASCII string. |
3316 Access<ScannerConstants::Utf8Decoder> | 3316 Access<ScannerConstants::Utf8Decoder> |
3317 decoder(ScannerConstants::utf8_decoder()); | 3317 decoder(ScannerConstants::utf8_decoder()); |
3318 decoder->Reset(string.start(), string.length()); | 3318 decoder->Reset(string.start(), string.length()); |
3319 int chars = 0; | 3319 int chars = 0; |
3320 bool is_ascii = true; | |
3321 while (decoder->has_more()) { | 3320 while (decoder->has_more()) { |
3322 uc32 r = decoder->GetNext(); | 3321 decoder->GetNext(); |
3323 if (r > String::kMaxAsciiCharCode) is_ascii = false; | |
3324 chars++; | 3322 chars++; |
3325 } | 3323 } |
3326 | 3324 |
3327 // If the string is ascii, we do not need to convert the characters | |
3328 // since UTF8 is backwards compatible with ascii. | |
3329 if (is_ascii) return AllocateStringFromAscii(string, pretenure); | |
3330 | |
3331 Object* result; | 3325 Object* result; |
3332 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); | 3326 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure); |
3333 if (!maybe_result->ToObject(&result)) return maybe_result; | 3327 if (!maybe_result->ToObject(&result)) return maybe_result; |
3334 } | 3328 } |
3335 | 3329 |
3336 // Convert and copy the characters into the new object. | 3330 // Convert and copy the characters into the new object. |
3337 String* string_result = String::cast(result); | 3331 String* string_result = String::cast(result); |
3338 decoder->Reset(string.start(), string.length()); | 3332 decoder->Reset(string.start(), string.length()); |
3339 for (int i = 0; i < chars; i++) { | 3333 for (int i = 0; i < chars; i++) { |
3340 uc32 r = decoder->GetNext(); | 3334 uc32 r = decoder->GetNext(); |
(...skipping 2178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5519 void ExternalStringTable::TearDown() { | 5513 void ExternalStringTable::TearDown() { |
5520 new_space_strings_.Free(); | 5514 new_space_strings_.Free(); |
5521 old_space_strings_.Free(); | 5515 old_space_strings_.Free(); |
5522 } | 5516 } |
5523 | 5517 |
5524 | 5518 |
5525 List<Object*> ExternalStringTable::new_space_strings_; | 5519 List<Object*> ExternalStringTable::new_space_strings_; |
5526 List<Object*> ExternalStringTable::old_space_strings_; | 5520 List<Object*> ExternalStringTable::old_space_strings_; |
5527 | 5521 |
5528 } } // namespace v8::internal | 5522 } } // namespace v8::internal |
OLD | NEW |