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 3628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3639 while (ia->has_more()) { | 3639 while (ia->has_more()) { |
| 3640 uc32 ca = ia->GetNext(); | 3640 uc32 ca = ia->GetNext(); |
| 3641 uc32 cb = ib->GetNext(); | 3641 uc32 cb = ib->GetNext(); |
| 3642 if (ca != cb) | 3642 if (ca != cb) |
| 3643 return false; | 3643 return false; |
| 3644 } | 3644 } |
| 3645 return true; | 3645 return true; |
| 3646 } | 3646 } |
| 3647 | 3647 |
| 3648 | 3648 |
| 3649 // Compares the contents of two strings by reading and comparing | |
| 3650 // int-sized blocks of characters. | |
| 3651 template <typename Char> | |
| 3652 static inline bool CompareRawStringContents(Vector<Char> a, Vector<Char> b) { | |
|
bak
2008/10/20 10:50:42
How about an assert checking a.length() == b.lengt
| |
| 3653 // Lint complains about taking sizeof a type rather than a variable. | |
| 3654 // That's just idiotic in this case so I'm turning it off here. | |
| 3655 const int kStepSize = sizeof(int) / sizeof(Char); // NOLINT | |
| 3656 int length = a.length(); | |
| 3657 int endpoint = length - kStepSize; | |
| 3658 const Char* pa = a.start(); | |
| 3659 const Char* pb = b.start(); | |
| 3660 int i; | |
| 3661 // Compare blocks until we reach near the end of the string. | |
| 3662 for (i = 0; i <= endpoint; i += kStepSize) { | |
|
Erik Corry
2008/10/20 09:40:04
If length = 3 then endpoint = 1, so we get into th
Christian Plesner Hansen
2008/10/20 09:52:09
If sizeof(Char) is 2 then endpoint is indeed 1 but
| |
| 3663 uint32_t wa = *reinterpret_cast<const uint32_t*>(pa + i); | |
| 3664 uint32_t wb = *reinterpret_cast<const uint32_t*>(pb + i); | |
| 3665 if (wa != wb) | |
|
bak
2008/10/20 10:50:42
Move return false to previous line or add {}.
| |
| 3666 return false; | |
| 3667 } | |
| 3668 // Compare the remaining characters that didn't fit into a block. | |
| 3669 for (; i < length; i++) | |
|
bak
2008/10/20 10:50:42
Missing {}
| |
| 3670 if (a[i] != b[i]) | |
| 3671 return false; | |
| 3672 return true; | |
| 3673 } | |
| 3674 | |
| 3675 | |
| 3649 static StringInputBuffer string_compare_buffer_b; | 3676 static StringInputBuffer string_compare_buffer_b; |
| 3650 | 3677 |
| 3651 | 3678 |
| 3652 template <typename IteratorA> | 3679 template <typename IteratorA> |
| 3653 static inline bool CompareStringContentsPartial(IteratorA* ia, String* b) { | 3680 static inline bool CompareStringContentsPartial(IteratorA* ia, String* b) { |
| 3654 if (b->IsFlat()) { | 3681 if (b->IsFlat()) { |
| 3655 if (b->IsAsciiRepresentation()) { | 3682 if (b->IsAsciiRepresentation()) { |
| 3656 VectorIterator<char> ib(b->ToAsciiVector()); | 3683 VectorIterator<char> ib(b->ToAsciiVector()); |
| 3657 return CompareStringContents(ia, &ib); | 3684 return CompareStringContents(ia, &ib); |
| 3658 } else { | 3685 } else { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 3674 int len = length(); | 3701 int len = length(); |
| 3675 if (len != other->length()) return false; | 3702 if (len != other->length()) return false; |
| 3676 if (len == 0) return true; | 3703 if (len == 0) return true; |
| 3677 | 3704 |
| 3678 // Fast check: if hash code is computed for both strings | 3705 // Fast check: if hash code is computed for both strings |
| 3679 // a fast negative check can be performed. | 3706 // a fast negative check can be performed. |
| 3680 if (HasHashCode() && other->HasHashCode()) { | 3707 if (HasHashCode() && other->HasHashCode()) { |
| 3681 if (Hash() != other->Hash()) return false; | 3708 if (Hash() != other->Hash()) return false; |
| 3682 } | 3709 } |
| 3683 | 3710 |
| 3711 if (this->IsSeqAsciiString() && other->IsSeqAsciiString()) { | |
| 3712 const char* str1 = SeqAsciiString::cast(this)->GetChars(); | |
| 3713 const char* str2 = SeqAsciiString::cast(other)->GetChars(); | |
| 3714 return CompareRawStringContents(Vector<const char>(str1, len), | |
| 3715 Vector<const char>(str2, len)); | |
| 3716 } | |
| 3717 | |
| 3684 if (this->IsFlat()) { | 3718 if (this->IsFlat()) { |
| 3685 if (this->IsAsciiRepresentation()) { | 3719 if (this->IsAsciiRepresentation()) { |
| 3686 VectorIterator<char> buf1(this->ToAsciiVector()); | 3720 Vector<const char> vec1 = this->ToAsciiVector(); |
| 3687 return CompareStringContentsPartial(&buf1, other); | 3721 if (other->IsFlat()) { |
| 3722 if (other->IsAsciiRepresentation()) { | |
| 3723 Vector<const char> vec2 = other->ToAsciiVector(); | |
| 3724 return CompareRawStringContents(vec1, vec2); | |
| 3725 } else { | |
| 3726 VectorIterator<char> buf1(vec1); | |
| 3727 VectorIterator<uc16> ib(other->ToUC16Vector()); | |
| 3728 return CompareStringContents(&buf1, &ib); | |
| 3729 } | |
| 3730 } else { | |
| 3731 VectorIterator<char> buf1(vec1); | |
| 3732 string_compare_buffer_b.Reset(0, other); | |
| 3733 return CompareStringContents(&buf1, &string_compare_buffer_b); | |
| 3734 } | |
| 3688 } else { | 3735 } else { |
| 3689 VectorIterator<uc16> buf1(this->ToUC16Vector()); | 3736 Vector<const uc16> vec1 = this->ToUC16Vector(); |
| 3690 return CompareStringContentsPartial(&buf1, other); | 3737 if (other->IsFlat()) { |
| 3738 if (other->IsAsciiRepresentation()) { | |
| 3739 VectorIterator<uc16> buf1(vec1); | |
| 3740 VectorIterator<char> ib(other->ToAsciiVector()); | |
| 3741 return CompareStringContents(&buf1, &ib); | |
| 3742 } else { | |
| 3743 Vector<const uc16> vec2(other->ToUC16Vector()); | |
| 3744 return CompareRawStringContents(vec1, vec2); | |
| 3745 } | |
| 3746 } else { | |
| 3747 VectorIterator<uc16> buf1(vec1); | |
| 3748 string_compare_buffer_b.Reset(0, other); | |
| 3749 return CompareStringContents(&buf1, &string_compare_buffer_b); | |
| 3750 } | |
| 3691 } | 3751 } |
| 3692 } else { | 3752 } else { |
| 3693 string_compare_buffer_a.Reset(0, this); | 3753 string_compare_buffer_a.Reset(0, this); |
| 3694 return CompareStringContentsPartial(&string_compare_buffer_a, other); | 3754 return CompareStringContentsPartial(&string_compare_buffer_a, other); |
| 3695 } | 3755 } |
| 3696 } | 3756 } |
| 3697 | 3757 |
| 3698 | 3758 |
| 3699 bool String::MarkAsUndetectable() { | 3759 bool String::MarkAsUndetectable() { |
| 3700 if (this->IsSymbol()) return false; | 3760 if (this->IsSymbol()) return false; |
| (...skipping 2707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6408 // No break point. | 6468 // No break point. |
| 6409 if (break_point_objects()->IsUndefined()) return 0; | 6469 if (break_point_objects()->IsUndefined()) return 0; |
| 6410 // Single beak point. | 6470 // Single beak point. |
| 6411 if (!break_point_objects()->IsFixedArray()) return 1; | 6471 if (!break_point_objects()->IsFixedArray()) return 1; |
| 6412 // Multiple break points. | 6472 // Multiple break points. |
| 6413 return FixedArray::cast(break_point_objects())->length(); | 6473 return FixedArray::cast(break_point_objects())->length(); |
| 6414 } | 6474 } |
| 6415 | 6475 |
| 6416 | 6476 |
| 6417 } } // namespace v8::internal | 6477 } } // namespace v8::internal |
| OLD | NEW |