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

Side by Side Diff: src/elements.cc

Issue 1196163005: Cleanup adding elements and in particular dictionary elements (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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 | « no previous file | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/elements.h" 9 #include "src/elements.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 Map* map = elements->map(); 982 Map* map = elements->map();
983 DCHECK((IsFastSmiOrObjectElementsKind(KindTraits::Kind) && 983 DCHECK((IsFastSmiOrObjectElementsKind(KindTraits::Kind) &&
984 (map == isolate->heap()->fixed_array_map() || 984 (map == isolate->heap()->fixed_array_map() ||
985 map == isolate->heap()->fixed_cow_array_map())) || 985 map == isolate->heap()->fixed_cow_array_map())) ||
986 (IsFastDoubleElementsKind(KindTraits::Kind) == 986 (IsFastDoubleElementsKind(KindTraits::Kind) ==
987 ((map == isolate->heap()->fixed_array_map() && length == 0) || 987 ((map == isolate->heap()->fixed_array_map() && length == 0) ||
988 map == isolate->heap()->fixed_double_array_map()))); 988 map == isolate->heap()->fixed_double_array_map())));
989 if (length == 0) return; // nothing to do! 989 if (length == 0) return; // nothing to do!
990 DisallowHeapAllocation no_gc; 990 DisallowHeapAllocation no_gc;
991 Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements); 991 Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements);
992 for (int i = 0; i < length; i++) { 992 if (IsFastSmiElementsKind(KindTraits::Kind)) {
993 DCHECK((!IsFastSmiElementsKind(KindTraits::Kind) || 993 for (int i = 0; i < length; i++) {
994 BackingStore::get(backing_store, i)->IsSmi()) || 994 DCHECK(BackingStore::get(backing_store, i)->IsSmi() ||
995 (IsFastHoleyElementsKind(KindTraits::Kind) == 995 (IsFastHoleyElementsKind(KindTraits::Kind) &&
996 backing_store->is_the_hole(i))); 996 backing_store->is_the_hole(i)));
997 }
997 } 998 }
998 #endif 999 #endif
999 } 1000 }
1000 }; 1001 };
1001 1002
1002 1003
1003 static inline ElementsKind ElementsKindForArray(FixedArrayBase* array) { 1004 static inline ElementsKind ElementsKindForArray(FixedArrayBase* array) {
1004 switch (array->map()->instance_type()) { 1005 switch (array->map()->instance_type()) {
1005 case FIXED_ARRAY_TYPE: 1006 case FIXED_ARRAY_TYPE:
1006 if (array->IsDictionary()) { 1007 if (array->IsDictionary()) {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 dict->SetEntry(i, the_hole_value, the_hole_value); 1339 dict->SetEntry(i, the_hole_value, the_hole_value);
1339 removed_entries++; 1340 removed_entries++;
1340 } 1341 }
1341 } 1342 }
1342 } 1343 }
1343 1344
1344 // Update the number of elements. 1345 // Update the number of elements.
1345 dict->ElementsRemoved(removed_entries); 1346 dict->ElementsRemoved(removed_entries);
1346 } 1347 }
1347 1348
1348 if (length <= Smi::kMaxValue) { 1349 Handle<Object> length_obj = isolate->factory()->NewNumberFromUint(length);
1349 array->set_length(Smi::FromInt(length)); 1350 array->set_length(*length_obj);
1350 } else {
1351 Handle<Object> length_obj = isolate->factory()->NewNumberFromUint(length);
1352 array->set_length(*length_obj);
1353 }
1354 } 1351 }
1355 1352
1356 static void DeleteCommon(Handle<JSObject> obj, uint32_t key, 1353 static void DeleteCommon(Handle<JSObject> obj, uint32_t key,
1357 LanguageMode language_mode) { 1354 LanguageMode language_mode) {
1358 Isolate* isolate = obj->GetIsolate(); 1355 Isolate* isolate = obj->GetIsolate();
1359 Handle<FixedArray> backing_store(FixedArray::cast(obj->elements()), 1356 Handle<FixedArray> backing_store(FixedArray::cast(obj->elements()),
1360 isolate); 1357 isolate);
1361 bool is_arguments = 1358 bool is_arguments =
1362 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); 1359 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS);
1363 if (is_arguments) { 1360 if (is_arguments) {
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 break; 1820 break;
1824 } 1821 }
1825 1822
1826 array->set_elements(*elms); 1823 array->set_elements(*elms);
1827 array->set_length(Smi::FromInt(number_of_elements)); 1824 array->set_length(Smi::FromInt(number_of_elements));
1828 return array; 1825 return array;
1829 } 1826 }
1830 1827
1831 } // namespace internal 1828 } // namespace internal
1832 } // namespace v8 1829 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698