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

Side by Side Diff: src/elements.cc

Issue 1209983002: Only try to delete dictionary elements if the length is actually reduced (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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 | 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 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 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} 1365 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {}
1366 1366
1367 static void SetLengthImpl(Handle<JSArray> array, uint32_t length, 1367 static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
1368 Handle<FixedArrayBase> backing_store) { 1368 Handle<FixedArrayBase> backing_store) {
1369 Handle<SeededNumberDictionary> dict = 1369 Handle<SeededNumberDictionary> dict =
1370 Handle<SeededNumberDictionary>::cast(backing_store); 1370 Handle<SeededNumberDictionary>::cast(backing_store);
1371 Isolate* isolate = array->GetIsolate(); 1371 Isolate* isolate = array->GetIsolate();
1372 int capacity = dict->Capacity(); 1372 int capacity = dict->Capacity();
1373 uint32_t old_length = 0; 1373 uint32_t old_length = 0;
1374 CHECK(array->length()->ToArrayLength(&old_length)); 1374 CHECK(array->length()->ToArrayLength(&old_length));
1375 if (dict->requires_slow_elements() && length < old_length) { 1375 if (length < old_length) {
1376 // Find last non-deletable element in range of elements to be 1376 if (dict->requires_slow_elements()) {
1377 // deleted and adjust range accordingly. 1377 // Find last non-deletable element in range of elements to be
1378 for (int i = 0; i < capacity; i++) { 1378 // deleted and adjust range accordingly.
1379 DisallowHeapAllocation no_gc; 1379 for (int i = 0; i < capacity; i++) {
1380 Object* key = dict->KeyAt(i); 1380 DisallowHeapAllocation no_gc;
1381 if (key->IsNumber()) { 1381 Object* key = dict->KeyAt(i);
1382 uint32_t number = static_cast<uint32_t>(key->Number()); 1382 if (key->IsNumber()) {
1383 if (length <= number && number < old_length) { 1383 uint32_t number = static_cast<uint32_t>(key->Number());
1384 PropertyDetails details = dict->DetailsAt(i); 1384 if (length <= number && number < old_length) {
1385 if (!details.IsConfigurable()) length = number + 1; 1385 PropertyDetails details = dict->DetailsAt(i);
1386 } 1386 if (!details.IsConfigurable()) length = number + 1;
1387 } 1387 }
1388 }
1389 }
1390
1391 if (length == 0) {
1392 // Flush the backing store.
1393 JSObject::ResetElements(array);
1394 } else {
1395 DisallowHeapAllocation no_gc;
1396 // Remove elements that should be deleted.
1397 int removed_entries = 0;
1398 Handle<Object> the_hole_value = isolate->factory()->the_hole_value();
1399 for (int i = 0; i < capacity; i++) {
1400 Object* key = dict->KeyAt(i);
1401 if (key->IsNumber()) {
1402 uint32_t number = static_cast<uint32_t>(key->Number());
1403 if (length <= number && number < old_length) {
1404 dict->SetEntry(i, the_hole_value, the_hole_value);
1405 removed_entries++;
1406 } 1388 }
1407 } 1389 }
1408 } 1390 }
1409 1391
1410 // Update the number of elements. 1392 if (length == 0) {
1411 dict->ElementsRemoved(removed_entries); 1393 // Flush the backing store.
1394 JSObject::ResetElements(array);
1395 } else {
1396 DisallowHeapAllocation no_gc;
1397 // Remove elements that should be deleted.
1398 int removed_entries = 0;
1399 Handle<Object> the_hole_value = isolate->factory()->the_hole_value();
1400 for (int i = 0; i < capacity; i++) {
1401 Object* key = dict->KeyAt(i);
1402 if (key->IsNumber()) {
1403 uint32_t number = static_cast<uint32_t>(key->Number());
1404 if (length <= number && number < old_length) {
1405 dict->SetEntry(i, the_hole_value, the_hole_value);
1406 removed_entries++;
1407 }
1408 }
1409 }
1410
1411 // Update the number of elements.
1412 dict->ElementsRemoved(removed_entries);
1413 }
1412 } 1414 }
1413 1415
1414 Handle<Object> length_obj = isolate->factory()->NewNumberFromUint(length); 1416 Handle<Object> length_obj = isolate->factory()->NewNumberFromUint(length);
1415 array->set_length(*length_obj); 1417 array->set_length(*length_obj);
1416 } 1418 }
1417 1419
1418 static void DeleteCommon(Handle<JSObject> obj, uint32_t key, 1420 static void DeleteCommon(Handle<JSObject> obj, uint32_t key,
1419 LanguageMode language_mode) { 1421 LanguageMode language_mode) {
1420 Isolate* isolate = obj->GetIsolate(); 1422 Isolate* isolate = obj->GetIsolate();
1421 Handle<FixedArray> backing_store(FixedArray::cast(obj->elements()), 1423 Handle<FixedArray> backing_store(FixedArray::cast(obj->elements()),
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 break; 1969 break;
1968 } 1970 }
1969 1971
1970 array->set_elements(*elms); 1972 array->set_elements(*elms);
1971 array->set_length(Smi::FromInt(number_of_elements)); 1973 array->set_length(Smi::FromInt(number_of_elements));
1972 return array; 1974 return array;
1973 } 1975 }
1974 1976
1975 } // namespace internal 1977 } // namespace internal
1976 } // namespace v8 1978 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698