| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 473 |
| 474 | 474 |
| 475 Handle<String> Factory::NewProperSubString(Handle<String> str, | 475 Handle<String> Factory::NewProperSubString(Handle<String> str, |
| 476 int begin, | 476 int begin, |
| 477 int end) { | 477 int end) { |
| 478 #if VERIFY_HEAP | 478 #if VERIFY_HEAP |
| 479 if (FLAG_verify_heap) str->StringVerify(); | 479 if (FLAG_verify_heap) str->StringVerify(); |
| 480 #endif | 480 #endif |
| 481 ASSERT(begin > 0 || end < str->length()); | 481 ASSERT(begin > 0 || end < str->length()); |
| 482 | 482 |
| 483 str = FlattenGetString(str); |
| 484 |
| 483 int length = end - begin; | 485 int length = end - begin; |
| 484 if (length <= 0) return empty_string(); | 486 if (length <= 0) return empty_string(); |
| 485 if (length == 1) { | 487 if (length == 1) { |
| 486 return LookupSingleCharacterStringFromCode(isolate(), str->Get(begin)); | 488 return LookupSingleCharacterStringFromCode(isolate(), str->Get(begin)); |
| 487 } | 489 } |
| 488 if (length == 2) { | 490 if (length == 2) { |
| 489 // Optimization for 2-byte strings often used as keys in a decompression | 491 // Optimization for 2-byte strings often used as keys in a decompression |
| 490 // dictionary. Check whether we already have the string in the string | 492 // dictionary. Check whether we already have the string in the string |
| 491 // table to prevent creation of many unnecessary strings. | 493 // table to prevent creation of many unnecessary strings. |
| 492 uint16_t c1 = str->Get(begin); | 494 uint16_t c1 = str->Get(begin); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 507 ASSERT(!result.is_null()); | 509 ASSERT(!result.is_null()); |
| 508 uc16* dest = result->GetChars(); | 510 uc16* dest = result->GetChars(); |
| 509 DisallowHeapAllocation no_gc; | 511 DisallowHeapAllocation no_gc; |
| 510 String::WriteToFlat(*str, dest, begin, end); | 512 String::WriteToFlat(*str, dest, begin, end); |
| 511 return result; | 513 return result; |
| 512 } | 514 } |
| 513 } | 515 } |
| 514 | 516 |
| 515 int offset = begin; | 517 int offset = begin; |
| 516 | 518 |
| 517 while (str->IsConsString()) { | |
| 518 Handle<ConsString> cons = Handle<ConsString>::cast(str); | |
| 519 int split = cons->first()->length(); | |
| 520 if (split <= offset) { | |
| 521 // Slice is fully contained in the second part. | |
| 522 str = Handle<String>(cons->second(), isolate()); | |
| 523 offset -= split; // Adjust for offset. | |
| 524 continue; | |
| 525 } else if (offset + length <= split) { | |
| 526 // Slice is fully contained in the first part. | |
| 527 str = Handle<String>(cons->first(), isolate()); | |
| 528 continue; | |
| 529 } | |
| 530 break; | |
| 531 } | |
| 532 | |
| 533 if (str->IsSlicedString()) { | 519 if (str->IsSlicedString()) { |
| 534 Handle<SlicedString> slice = Handle<SlicedString>::cast(str); | 520 Handle<SlicedString> slice = Handle<SlicedString>::cast(str); |
| 535 str = Handle<String>(slice->parent(), isolate()); | 521 str = Handle<String>(slice->parent(), isolate()); |
| 536 offset += slice->offset(); | 522 offset += slice->offset(); |
| 537 } else { | |
| 538 str = FlattenGetString(str); | |
| 539 } | 523 } |
| 540 | 524 |
| 541 ASSERT(str->IsSeqString() || str->IsExternalString()); | 525 ASSERT(str->IsSeqString() || str->IsExternalString()); |
| 542 Handle<SlicedString> slice = NewRawSlicedString( | 526 Handle<SlicedString> slice = NewRawSlicedString( |
| 543 str->IsOneByteRepresentation() ? String::ONE_BYTE_ENCODING | 527 str->IsOneByteRepresentation() ? String::ONE_BYTE_ENCODING |
| 544 : String::TWO_BYTE_ENCODING); | 528 : String::TWO_BYTE_ENCODING); |
| 545 | 529 |
| 546 slice->set_hash_field(String::kEmptyHashField); | 530 slice->set_hash_field(String::kEmptyHashField); |
| 547 slice->set_length(length); | 531 slice->set_length(length); |
| 548 slice->set_parent(*str); | 532 slice->set_parent(*str); |
| (...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2017 return Handle<Object>::null(); | 2001 return Handle<Object>::null(); |
| 2018 } | 2002 } |
| 2019 | 2003 |
| 2020 | 2004 |
| 2021 Handle<Object> Factory::ToBoolean(bool value) { | 2005 Handle<Object> Factory::ToBoolean(bool value) { |
| 2022 return value ? true_value() : false_value(); | 2006 return value ? true_value() : false_value(); |
| 2023 } | 2007 } |
| 2024 | 2008 |
| 2025 | 2009 |
| 2026 } } // namespace v8::internal | 2010 } } // namespace v8::internal |
| OLD | NEW |