| OLD | NEW | 
|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "src/objects.h" | 5 #include "src/objects.h" | 
| 6 | 6 | 
| 7 #include <cmath> | 7 #include <cmath> | 
| 8 #include <iomanip> | 8 #include <iomanip> | 
| 9 #include <memory> | 9 #include <memory> | 
| 10 #include <sstream> | 10 #include <sstream> | 
| (...skipping 11690 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 11701     // Isolate the array index form the full hash field. | 11701     // Isolate the array index form the full hash field. | 
| 11702     *index = ArrayIndexValueBits::decode(field); | 11702     *index = ArrayIndexValueBits::decode(field); | 
| 11703     return true; | 11703     return true; | 
| 11704   } else { | 11704   } else { | 
| 11705     return ComputeArrayIndex(index); | 11705     return ComputeArrayIndex(index); | 
| 11706   } | 11706   } | 
| 11707 } | 11707 } | 
| 11708 | 11708 | 
| 11709 | 11709 | 
| 11710 Handle<String> SeqString::Truncate(Handle<SeqString> string, int new_length) { | 11710 Handle<String> SeqString::Truncate(Handle<SeqString> string, int new_length) { | 
|  | 11711   Heap* heap = string->GetHeap(); | 
|  | 11712   if (new_length == 0) return heap->isolate()->factory()->empty_string(); | 
|  | 11713 | 
| 11711   int new_size, old_size; | 11714   int new_size, old_size; | 
| 11712   int old_length = string->length(); | 11715   int old_length = string->length(); | 
| 11713   if (old_length <= new_length) return string; | 11716   if (old_length <= new_length) return string; | 
| 11714 | 11717 | 
| 11715   if (string->IsSeqOneByteString()) { | 11718   if (string->IsSeqOneByteString()) { | 
| 11716     old_size = SeqOneByteString::SizeFor(old_length); | 11719     old_size = SeqOneByteString::SizeFor(old_length); | 
| 11717     new_size = SeqOneByteString::SizeFor(new_length); | 11720     new_size = SeqOneByteString::SizeFor(new_length); | 
| 11718   } else { | 11721   } else { | 
| 11719     DCHECK(string->IsSeqTwoByteString()); | 11722     DCHECK(string->IsSeqTwoByteString()); | 
| 11720     old_size = SeqTwoByteString::SizeFor(old_length); | 11723     old_size = SeqTwoByteString::SizeFor(old_length); | 
| 11721     new_size = SeqTwoByteString::SizeFor(new_length); | 11724     new_size = SeqTwoByteString::SizeFor(new_length); | 
| 11722   } | 11725   } | 
| 11723 | 11726 | 
| 11724   int delta = old_size - new_size; | 11727   int delta = old_size - new_size; | 
| 11725 | 11728 | 
| 11726   Address start_of_string = string->address(); | 11729   Address start_of_string = string->address(); | 
| 11727   DCHECK_OBJECT_ALIGNED(start_of_string); | 11730   DCHECK_OBJECT_ALIGNED(start_of_string); | 
| 11728   DCHECK_OBJECT_ALIGNED(start_of_string + new_size); | 11731   DCHECK_OBJECT_ALIGNED(start_of_string + new_size); | 
| 11729 | 11732 | 
| 11730   Heap* heap = string->GetHeap(); |  | 
| 11731   // Sizes are pointer size aligned, so that we can use filler objects | 11733   // Sizes are pointer size aligned, so that we can use filler objects | 
| 11732   // that are a multiple of pointer size. | 11734   // that are a multiple of pointer size. | 
| 11733   heap->CreateFillerObjectAt(start_of_string + new_size, delta, | 11735   heap->CreateFillerObjectAt(start_of_string + new_size, delta, | 
| 11734                              ClearRecordedSlots::kNo); | 11736                              ClearRecordedSlots::kNo); | 
| 11735   heap->AdjustLiveBytes(*string, -delta); | 11737   heap->AdjustLiveBytes(*string, -delta); | 
| 11736 | 11738 | 
| 11737   // We are storing the new length using release store after creating a filler | 11739   // We are storing the new length using release store after creating a filler | 
| 11738   // for the left-over space to avoid races with the sweeper thread. | 11740   // for the left-over space to avoid races with the sweeper thread. | 
| 11739   string->synchronized_set_length(new_length); | 11741   string->synchronized_set_length(new_length); | 
| 11740 | 11742 | 
| 11741   if (new_length == 0) return heap->isolate()->factory()->empty_string(); |  | 
| 11742   return string; | 11743   return string; | 
| 11743 } | 11744 } | 
| 11744 | 11745 | 
| 11745 | 11746 | 
| 11746 uint32_t StringHasher::MakeArrayIndexHash(uint32_t value, int length) { | 11747 uint32_t StringHasher::MakeArrayIndexHash(uint32_t value, int length) { | 
| 11747   // For array indexes mix the length into the hash as an array index could | 11748   // For array indexes mix the length into the hash as an array index could | 
| 11748   // be zero. | 11749   // be zero. | 
| 11749   DCHECK(length > 0); | 11750   DCHECK(length > 0); | 
| 11750   DCHECK(length <= String::kMaxArrayIndexSize); | 11751   DCHECK(length <= String::kMaxArrayIndexSize); | 
| 11751   DCHECK(TenToThe(String::kMaxCachedArrayIndexLength) < | 11752   DCHECK(TenToThe(String::kMaxCachedArrayIndexLength) < | 
| (...skipping 8456 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 20208       // depend on this. | 20209       // depend on this. | 
| 20209       return DICTIONARY_ELEMENTS; | 20210       return DICTIONARY_ELEMENTS; | 
| 20210     } | 20211     } | 
| 20211     DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20212     DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 
| 20212     return kind; | 20213     return kind; | 
| 20213   } | 20214   } | 
| 20214 } | 20215 } | 
| 20215 | 20216 | 
| 20216 }  // namespace internal | 20217 }  // namespace internal | 
| 20217 }  // namespace v8 | 20218 }  // namespace v8 | 
| OLD | NEW | 
|---|