Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1335 share->set_function_data(undefined_value()); | 1335 share->set_function_data(undefined_value()); |
| 1336 share->set_lazy_load_data(undefined_value()); | 1336 share->set_lazy_load_data(undefined_value()); |
| 1337 share->set_script(undefined_value()); | 1337 share->set_script(undefined_value()); |
| 1338 share->set_start_position_and_type(0); | 1338 share->set_start_position_and_type(0); |
| 1339 share->set_debug_info(undefined_value()); | 1339 share->set_debug_info(undefined_value()); |
| 1340 return result; | 1340 return result; |
| 1341 } | 1341 } |
| 1342 | 1342 |
| 1343 | 1343 |
| 1344 Object* Heap::AllocateConsString(String* first, String* second) { | 1344 Object* Heap::AllocateConsString(String* first, String* second) { |
| 1345 int length = first->length() + second->length(); | 1345 int first_length = first->length(); |
| 1346 int second_length = second->length(); | |
| 1347 int length = first_length + second_length; | |
| 1346 bool is_ascii = first->is_ascii_representation() | 1348 bool is_ascii = first->is_ascii_representation() |
| 1347 && second->is_ascii_representation(); | 1349 && second->is_ascii_representation(); |
| 1348 | 1350 |
| 1349 // If the resulting string is small make a flat string. | 1351 // If the resulting string is small make a flat string. |
| 1350 if (length < ConsString::kMinLength) { | 1352 if (length < String::kMinNonFlatLength) { |
| 1351 Object* result = is_ascii | 1353 ASSERT(first->IsFlat()); |
| 1352 ? AllocateRawAsciiString(length) | 1354 ASSERT(second->IsFlat()); |
| 1353 : AllocateRawTwoByteString(length); | 1355 if (is_ascii) { |
| 1354 if (result->IsFailure()) return result; | 1356 Object* result = AllocateRawAsciiString(length); |
| 1355 // Copy the characters into the new object. | 1357 if (result->IsFailure()) return result; |
| 1356 String* string_result = String::cast(result); | 1358 // Copy the characters into the new object. |
| 1357 int first_length = first->length(); | 1359 byte* dest = SeqAsciiString::cast(result)->GetCharsAddress(); |
|
Christian Plesner Hansen
2008/10/21 14:16:22
There is some confusion about whether to use char
Erik Corry
2008/10/22 11:59:48
I've tried to use char consistently, since the nam
| |
| 1358 // Copy the content of the first string. | 1360 String::WriteToFlat(first, dest, 0, first_length); |
| 1359 for (int i = 0; i < first_length; i++) { | 1361 String::WriteToFlat(second, dest + first_length, 0, second_length); |
| 1360 string_result->Set(i, first->Get(i)); | 1362 return result; |
| 1363 } else { | |
| 1364 Object* result = AllocateRawTwoByteString(length); | |
| 1365 if (result->IsFailure()) return result; | |
| 1366 // Copy the characters into the new object. | |
| 1367 uc16* dest = reinterpret_cast<uc16*>( | |
| 1368 SeqTwoByteString::cast(result)->GetCharsAddress()); | |
| 1369 String::WriteToFlat(first, dest, 0, first_length); | |
| 1370 String::WriteToFlat(second, dest + first_length, 0, second_length); | |
| 1371 return result; | |
| 1361 } | 1372 } |
| 1362 int second_length = second->length(); | |
| 1363 // Copy the content of the first string. | |
| 1364 for (int i = 0; i < second_length; i++) { | |
| 1365 string_result->Set(first_length + i, second->Get(i)); | |
| 1366 } | |
| 1367 return result; | |
| 1368 } | 1373 } |
| 1369 | 1374 |
| 1370 Map* map; | 1375 Map* map; |
| 1371 if (length <= String::kMaxShortStringSize) { | 1376 if (length <= String::kMaxShortStringSize) { |
| 1372 map = is_ascii ? short_cons_ascii_string_map() | 1377 map = is_ascii ? short_cons_ascii_string_map() |
| 1373 : short_cons_string_map(); | 1378 : short_cons_string_map(); |
| 1374 } else if (length <= String::kMaxMediumStringSize) { | 1379 } else if (length <= String::kMaxMediumStringSize) { |
| 1375 map = is_ascii ? medium_cons_ascii_string_map() | 1380 map = is_ascii ? medium_cons_ascii_string_map() |
| 1376 : medium_cons_string_map(); | 1381 : medium_cons_string_map(); |
| 1377 } else { | 1382 } else { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1388 cons_string->set_length(length); | 1393 cons_string->set_length(length); |
| 1389 | 1394 |
| 1390 return result; | 1395 return result; |
| 1391 } | 1396 } |
| 1392 | 1397 |
| 1393 | 1398 |
| 1394 Object* Heap::AllocateSlicedString(String* buffer, int start, int end) { | 1399 Object* Heap::AllocateSlicedString(String* buffer, int start, int end) { |
| 1395 int length = end - start; | 1400 int length = end - start; |
| 1396 | 1401 |
| 1397 // If the resulting string is small make a sub string. | 1402 // If the resulting string is small make a sub string. |
| 1398 if (end - start <= SlicedString::kMinLength) { | 1403 if (end - start <= String::kMinNonFlatLength) { |
| 1399 return Heap::AllocateSubString(buffer, start, end); | 1404 return Heap::AllocateSubString(buffer, start, end); |
| 1400 } | 1405 } |
| 1401 | 1406 |
| 1402 Map* map; | 1407 Map* map; |
| 1403 if (length <= String::kMaxShortStringSize) { | 1408 if (length <= String::kMaxShortStringSize) { |
| 1404 map = buffer->is_ascii_representation() ? short_sliced_ascii_string_map() | 1409 map = buffer->is_ascii_representation() ? short_sliced_ascii_string_map() |
| 1405 : short_sliced_string_map(); | 1410 : short_sliced_string_map(); |
| 1406 } else if (length <= String::kMaxMediumStringSize) { | 1411 } else if (length <= String::kMaxMediumStringSize) { |
| 1407 map = buffer->is_ascii_representation() ? medium_sliced_ascii_string_map() | 1412 map = buffer->is_ascii_representation() ? medium_sliced_ascii_string_map() |
| 1408 : medium_sliced_string_map(); | 1413 : medium_sliced_string_map(); |
| (...skipping 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3124 #ifdef DEBUG | 3129 #ifdef DEBUG |
| 3125 bool Heap::GarbageCollectionGreedyCheck() { | 3130 bool Heap::GarbageCollectionGreedyCheck() { |
| 3126 ASSERT(FLAG_gc_greedy); | 3131 ASSERT(FLAG_gc_greedy); |
| 3127 if (Bootstrapper::IsActive()) return true; | 3132 if (Bootstrapper::IsActive()) return true; |
| 3128 if (disallow_allocation_failure()) return true; | 3133 if (disallow_allocation_failure()) return true; |
| 3129 return CollectGarbage(0, NEW_SPACE); | 3134 return CollectGarbage(0, NEW_SPACE); |
| 3130 } | 3135 } |
| 3131 #endif | 3136 #endif |
| 3132 | 3137 |
| 3133 } } // namespace v8::internal | 3138 } } // namespace v8::internal |
| OLD | NEW |