diff options
author | Matt Loring <mattloring@google.com> | 2016-07-20 13:37:45 -0700 |
---|---|---|
committer | Matt Loring <mattloring@google.com> | 2016-07-26 10:42:54 -0700 |
commit | e22ffefff221caee264ab0b88691478a03ab1862 (patch) | |
tree | f72c4eeb58b63ffebdd460a3bda32aaa758ba0b8 /deps | |
parent | a3d62bdbaa6e29854617ad010d2090461803cc79 (diff) | |
download | android-node-v8-e22ffefff221caee264ab0b88691478a03ab1862.tar.gz android-node-v8-e22ffefff221caee264ab0b88691478a03ab1862.tar.bz2 android-node-v8-e22ffefff221caee264ab0b88691478a03ab1862.zip |
deps: cherry-pick a76d133 from v8 upstream
Original commit message:
Fix incorrect parameter to HasSufficientCapacity
It takes the number of additional elements, not the total target
capacity.
Also, avoid right-shifting a negative integer as this is undefined in
general
BUG=v8:4909
R=verwaest@chromium.org
Review-Url: https://codereview.chromium.org/2162333002
Cr-Commit-Position: refs/heads/master@{#37901}
Fixes: https://github.com/nodejs/node/issues/6180
PR-URL: https://github.com/nodejs/node/pull/7689
Reviewed-By: Matt Loring <mattloring@google.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps')
-rw-r--r-- | deps/v8/src/objects.cc | 18 | ||||
-rw-r--r-- | deps/v8/src/objects.h | 2 |
2 files changed, 10 insertions, 10 deletions
diff --git a/deps/v8/src/objects.cc b/deps/v8/src/objects.cc index c86806811c..51993f3f32 100644 --- a/deps/v8/src/objects.cc +++ b/deps/v8/src/objects.cc @@ -17389,7 +17389,7 @@ Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity( int capacity = table->Capacity(); int nof = table->NumberOfElements() + n; - if (table->HasSufficientCapacity(n)) return table; + if (table->HasSufficientCapacityToAdd(n)) return table; const int kMinCapacityForPretenure = 256; bool should_pretenure = pretenure == TENURED || @@ -17405,16 +17405,16 @@ Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity( return new_table; } - template <typename Derived, typename Shape, typename Key> -bool HashTable<Derived, Shape, Key>::HasSufficientCapacity(int n) { +bool HashTable<Derived, Shape, Key>::HasSufficientCapacityToAdd( + int number_of_additional_elements) { int capacity = Capacity(); - int nof = NumberOfElements() + n; + int nof = NumberOfElements() + number_of_additional_elements; int nod = NumberOfDeletedElements(); // Return true if: - // 50% is still free after adding n elements and + // 50% is still free after adding number_of_additional_elements elements and // at most 50% of the free elements are deleted elements. - if (nod <= (capacity - nof) >> 1) { + if ((nof < capacity) && ((nod <= (capacity - nof) >> 1))) { int needed_free = nof >> 1; if (nof + needed_free <= capacity) return true; } @@ -18332,7 +18332,7 @@ void Dictionary<Derived, Shape, Key>::SetRequiresCopyOnCapacityChange() { DCHECK_EQ(0, DerivedHashTable::NumberOfDeletedElements()); // Make sure that HashTable::EnsureCapacity will create a copy. DerivedHashTable::SetNumberOfDeletedElements(DerivedHashTable::Capacity()); - DCHECK(!DerivedHashTable::HasSufficientCapacity(1)); + DCHECK(!DerivedHashTable::HasSufficientCapacityToAdd(1)); } @@ -18742,8 +18742,8 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table, } // If we're out of luck, we didn't get a GC recently, and so rehashing // isn't enough to avoid a crash. - int nof = table->NumberOfElements() + 1; - if (!table->HasSufficientCapacity(nof)) { + if (!table->HasSufficientCapacityToAdd(1)) { + int nof = table->NumberOfElements() + 1; int capacity = ObjectHashTable::ComputeCapacity(nof * 2); if (capacity > ObjectHashTable::kMaxCapacity) { for (size_t i = 0; i < 2; ++i) { diff --git a/deps/v8/src/objects.h b/deps/v8/src/objects.h index c825b42d84..abced2d4ba 100644 --- a/deps/v8/src/objects.h +++ b/deps/v8/src/objects.h @@ -3331,7 +3331,7 @@ class HashTable : public HashTableBase { PretenureFlag pretenure = NOT_TENURED); // Returns true if this table has sufficient capacity for adding n elements. - bool HasSufficientCapacity(int n); + bool HasSufficientCapacityToAdd(int number_of_additional_elements); // Sets the capacity of the hash table. void SetCapacity(int capacity) { |