Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: src/objects.cc

Issue 1316213008: Speedup JSReceiver::GetKeys (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: improvements Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 <iomanip> 7 #include <iomanip>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 7897 matching lines...) Expand 10 before | Expand all | Expand 10 after
7908 DisallowHeapAllocation no_allocation; 7908 DisallowHeapAllocation no_allocation;
7909 for (int i = 0; i < result->length(); i++) { 7909 for (int i = 0; i < result->length(); i++) {
7910 Object* current = result->get(i); 7910 Object* current = result->get(i);
7911 DCHECK(current->IsNumber() || current->IsName()); 7911 DCHECK(current->IsNumber() || current->IsName());
7912 } 7912 }
7913 } 7913 }
7914 #endif 7914 #endif
7915 return result; 7915 return result;
7916 } 7916 }
7917 7917
7918 namespace {
7918 7919
7919 MaybeHandle<FixedArray> FixedArray::UnionOfKeys(Handle<FixedArray> first, 7920 inline MaybeHandle<FixedArray> LinearUnionOfKeys(Isolate* isolate,
7920 Handle<FixedArray> second) { 7921 Handle<FixedArray> first,
7921 if (second->length() == 0) return first; 7922 Handle<FixedArray> second) {
7922 if (first->length() == 0) return second; 7923 int second_length = second->length();
7923 Isolate* isolate = first->GetIsolate(); 7924 int first_length = first->length();
7925
7924 Handle<FixedArray> result = 7926 Handle<FixedArray> result =
7925 isolate->factory()->NewFixedArray(first->length() + second->length()); 7927 isolate->factory()->NewFixedArray(first_length + second_length);
7926 for (int i = 0; i < first->length(); i++) { 7928 for (int i = 0; i < first_length; i++) {
7927 result->set(i, first->get(i)); 7929 result->set(i, first->get(i));
7928 } 7930 }
7929 int pos = first->length(); 7931 int pos = first_length;
7930 for (int j = 0; j < second->length(); j++) { 7932 for (int j = 0; j < second_length; j++) {
7931 Object* current = second->get(j); 7933 Object* current = second->get(j);
7932 int i; 7934 int i;
7933 for (i = 0; i < first->length(); i++) { 7935 for (i = 0; i < first_length; i++) {
7934 if (current->KeyEquals(first->get(i))) break; 7936 if (current->KeyEquals(first->get(i))) break;
7935 } 7937 }
7936 if (i == first->length()) { 7938 if (i == first_length) {
7937 result->set(pos++, current); 7939 result->set(pos++, current);
7938 } 7940 }
7939 } 7941 }
7940 7942
7941 result->Shrink(pos); 7943 result->Shrink(pos);
7942 return result; 7944 return result;
7943 } 7945 }
7944 7946
7947 inline MaybeHandle<FixedArray> SublinearUnionOfKeys(Isolate* isolate,
7948 Handle<FixedArray> first,
7949 Handle<FixedArray> second) {
7950 int second_length = second->length();
7951 int first_length = first->length();
7952
7953 Handle<FixedArray> result =
7954 isolate->factory()->NewFixedArray(first_length + second_length);
7955 Handle<ObjectHashTable> cache = ObjectHashTable::New(isolate, first_length);
7956
7957 for (int i = 0; i < first_length; i++) {
7958 Handle<Object> value(first->get(i), isolate);
7959 result->set(i, *value);
7960 ObjectHashTable::Put(isolate, cache, value, value);
7961 }
7962 int pos = first_length;
7963 for (int i = 0; i < second_length; i++) {
7964 Handle<Object> current(second->get(i), isolate);
7965 if (cache->HasKey(isolate, current)) {
7966 result->set(pos++, *current);
7967 }
7968 }
7969
7970 result->Shrink(pos);
7971 return result;
7972 }
7973
7974 } // namespace
7975
7976 MaybeHandle<FixedArray> FixedArray::UnionOfKeys(Handle<FixedArray> first,
7977 Handle<FixedArray> second) {
7978 int second_length = second->length();
7979 if (second_length == 0) return first;
7980 int first_length = first->length();
7981 if (first_length == 0) return second;
7982 Isolate* isolate = first->GetIsolate();
7983 if (first_length <= 2) {
7984 return LinearUnionOfKeys(isolate, first, second);
7985 }
7986 return SublinearUnionOfKeys(isolate, first, second);
7987 }
7988
7945 7989
7946 void FixedArray::CopyTo(int pos, FixedArray* dest, int dest_pos, int len) { 7990 void FixedArray::CopyTo(int pos, FixedArray* dest, int dest_pos, int len) {
7947 DisallowHeapAllocation no_gc; 7991 DisallowHeapAllocation no_gc;
7948 WriteBarrierMode mode = dest->GetWriteBarrierMode(no_gc); 7992 WriteBarrierMode mode = dest->GetWriteBarrierMode(no_gc);
7949 for (int index = 0; index < len; index++) { 7993 for (int index = 0; index < len; index++) {
7950 dest->set(dest_pos+index, get(pos+index), mode); 7994 dest->set(dest_pos+index, get(pos+index), mode);
7951 } 7995 }
7952 } 7996 }
7953 7997
7954 7998
(...skipping 7108 matching lines...) Expand 10 before | Expand all | Expand 10 after
15063 } 15107 }
15064 return Lookup(isolate, key, Smi::cast(hash)->value()); 15108 return Lookup(isolate, key, Smi::cast(hash)->value());
15065 } 15109 }
15066 15110
15067 15111
15068 Object* ObjectHashTable::Lookup(Handle<Object> key, int32_t hash) { 15112 Object* ObjectHashTable::Lookup(Handle<Object> key, int32_t hash) {
15069 return Lookup(GetIsolate(), key, hash); 15113 return Lookup(GetIsolate(), key, hash);
15070 } 15114 }
15071 15115
15072 15116
15117 bool ObjectHashTable::HasKey(Isolate* isolate, Handle<Object> key) {
15118 DisallowHeapAllocation no_gc;
15119 DCHECK(IsKey(*key));
15120
15121 // If the object does not have an identity hash, it was never used as a key.
15122 Object* hash = key->GetHash();
15123 if (hash->IsUndefined()) return false;
15124 int entry = FindEntry(isolate, key, Smi::cast(hash)->value());
15125 return entry != kNotFound;
15126 }
15127
15128
15073 Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table, 15129 Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
15074 Handle<Object> key, 15130 Handle<Object> key,
15075 Handle<Object> value) { 15131 Handle<Object> value) {
15076 DCHECK(table->IsKey(*key)); 15132 DCHECK(table->IsKey(*key));
15077 DCHECK(!value->IsTheHole()); 15133 DCHECK(!value->IsTheHole());
15078 15134
15079 Isolate* isolate = table->GetIsolate(); 15135 Isolate* isolate = table->GetIsolate();
15080 // Make sure the key object has an identity hash code. 15136 // Make sure the key object has an identity hash code.
15081 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); 15137 int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
15082 15138
(...skipping 18 matching lines...) Expand all
15101 return table; 15157 return table;
15102 } 15158 }
15103 15159
15104 // Check whether the hash table should be extended. 15160 // Check whether the hash table should be extended.
15105 table = EnsureCapacity(table, 1, key); 15161 table = EnsureCapacity(table, 1, key);
15106 table->AddEntry(table->FindInsertionEntry(hash), *key, *value); 15162 table->AddEntry(table->FindInsertionEntry(hash), *key, *value);
15107 return table; 15163 return table;
15108 } 15164 }
15109 15165
15110 15166
15167 Handle<ObjectHashTable> ObjectHashTable::Put(Isolate* isolate,
Camillo Bruni 2015/09/09 09:34:00 duplicated for tryout... has to be reverted
15168 Handle<ObjectHashTable> table,
15169 Handle<Object> key,
15170 Handle<Object> value) {
15171 DCHECK(table->IsKey(*key));
15172 DCHECK(!value->IsTheHole());
15173
15174 // Make sure the key object has an identity hash code.
15175 int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
15176
15177 return Put(isolate, table, key, value, hash);
15178 }
15179
15180
15181 Handle<ObjectHashTable> ObjectHashTable::Put(Isolate* isolate,
15182 Handle<ObjectHashTable> table,
15183 Handle<Object> key,
15184 Handle<Object> value,
15185 int32_t hash) {
Camillo Bruni 2015/09/09 09:34:00 again, test duplication
15186 DCHECK(table->IsKey(*key));
15187 DCHECK(!value->IsTheHole());
15188
15189 int entry = table->FindEntry(isolate, key, hash);
15190
15191 // Key is already in table, just overwrite value.
15192 if (entry != kNotFound) {
15193 table->set(EntryToIndex(entry) + 1, *value);
15194 return table;
15195 }
15196
15197 // Check whether the hash table should be extended.
15198 table = EnsureCapacity(table, 1, key);
15199 table->AddEntry(table->FindInsertionEntry(hash), *key, *value);
15200 return table;
15201 }
15202
15203
15111 Handle<ObjectHashTable> ObjectHashTable::Remove(Handle<ObjectHashTable> table, 15204 Handle<ObjectHashTable> ObjectHashTable::Remove(Handle<ObjectHashTable> table,
15112 Handle<Object> key, 15205 Handle<Object> key,
15113 bool* was_present) { 15206 bool* was_present) {
15114 DCHECK(table->IsKey(*key)); 15207 DCHECK(table->IsKey(*key));
15115 15208
15116 Object* hash = key->GetHash(); 15209 Object* hash = key->GetHash();
15117 if (hash->IsUndefined()) { 15210 if (hash->IsUndefined()) {
15118 *was_present = false; 15211 *was_present = false;
15119 return table; 15212 return table;
15120 } 15213 }
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
16164 if (cell->value() != *new_value) { 16257 if (cell->value() != *new_value) {
16165 cell->set_value(*new_value); 16258 cell->set_value(*new_value);
16166 Isolate* isolate = cell->GetIsolate(); 16259 Isolate* isolate = cell->GetIsolate();
16167 cell->dependent_code()->DeoptimizeDependentCodeGroup( 16260 cell->dependent_code()->DeoptimizeDependentCodeGroup(
16168 isolate, DependentCode::kPropertyCellChangedGroup); 16261 isolate, DependentCode::kPropertyCellChangedGroup);
16169 } 16262 }
16170 } 16263 }
16171 16264
16172 } // namespace internal 16265 } // namespace internal
16173 } // namespace v8 16266 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698