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 16710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16721 SetNumberOfDeletedElements(0); | 16721 SetNumberOfDeletedElements(0); |
16722 } | 16722 } |
16723 | 16723 |
16724 | 16724 |
16725 template<typename Derived, typename Shape, typename Key> | 16725 template<typename Derived, typename Shape, typename Key> |
16726 Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity( | 16726 Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity( |
16727 Handle<Derived> table, | 16727 Handle<Derived> table, |
16728 int n, | 16728 int n, |
16729 Key key, | 16729 Key key, |
16730 PretenureFlag pretenure) { | 16730 PretenureFlag pretenure) { |
| 16731 if (table->HasSufficientCapacityToAdd(n)) return table; |
| 16732 |
16731 Isolate* isolate = table->GetIsolate(); | 16733 Isolate* isolate = table->GetIsolate(); |
16732 int capacity = table->Capacity(); | 16734 int capacity = table->Capacity(); |
16733 int nof = table->NumberOfElements() + n; | 16735 int new_nof = table->NumberOfElements() + n; |
16734 | |
16735 if (table->HasSufficientCapacityToAdd(n)) return table; | |
16736 | 16736 |
16737 const int kMinCapacityForPretenure = 256; | 16737 const int kMinCapacityForPretenure = 256; |
16738 bool should_pretenure = pretenure == TENURED || | 16738 bool should_pretenure = pretenure == TENURED || |
16739 ((capacity > kMinCapacityForPretenure) && | 16739 ((capacity > kMinCapacityForPretenure) && |
16740 !isolate->heap()->InNewSpace(*table)); | 16740 !isolate->heap()->InNewSpace(*table)); |
16741 Handle<Derived> new_table = HashTable::New( | 16741 Handle<Derived> new_table = |
16742 isolate, | 16742 HashTable::New(isolate, new_nof, USE_DEFAULT_MINIMUM_CAPACITY, |
16743 nof * 2, | 16743 should_pretenure ? TENURED : NOT_TENURED); |
16744 USE_DEFAULT_MINIMUM_CAPACITY, | |
16745 should_pretenure ? TENURED : NOT_TENURED); | |
16746 | 16744 |
16747 table->Rehash(new_table, key); | 16745 table->Rehash(new_table, key); |
16748 return new_table; | 16746 return new_table; |
16749 } | 16747 } |
16750 | 16748 |
16751 template <typename Derived, typename Shape, typename Key> | 16749 template <typename Derived, typename Shape, typename Key> |
16752 bool HashTable<Derived, Shape, Key>::HasSufficientCapacityToAdd( | 16750 bool HashTable<Derived, Shape, Key>::HasSufficientCapacityToAdd( |
16753 int number_of_additional_elements) { | 16751 int number_of_additional_elements) { |
16754 int capacity = Capacity(); | 16752 int capacity = Capacity(); |
16755 int nof = NumberOfElements() + number_of_additional_elements; | 16753 int nof = NumberOfElements() + number_of_additional_elements; |
(...skipping 3923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20679 // depend on this. | 20677 // depend on this. |
20680 return DICTIONARY_ELEMENTS; | 20678 return DICTIONARY_ELEMENTS; |
20681 } | 20679 } |
20682 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20680 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
20683 return kind; | 20681 return kind; |
20684 } | 20682 } |
20685 } | 20683 } |
20686 | 20684 |
20687 } // namespace internal | 20685 } // namespace internal |
20688 } // namespace v8 | 20686 } // namespace v8 |
OLD | NEW |