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

Side by Side Diff: src/objects.cc

Issue 10911054: If we are trimming the whole array, just return the empty fixed array. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: u Created 8 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 | Annotate | Revision Log
« 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 12456 matching lines...) Expand 10 before | Expand all | Expand 10 after
12467 if ((attr & filter) == 0) storage->set(index++, k); 12467 if ((attr & filter) == 0) storage->set(index++, k);
12468 } 12468 }
12469 } 12469 }
12470 if (sort_mode == Dictionary<Shape, Key>::SORTED) { 12470 if (sort_mode == Dictionary<Shape, Key>::SORTED) {
12471 storage->SortPairs(storage, index); 12471 storage->SortPairs(storage, index);
12472 } 12472 }
12473 ASSERT(storage->length() >= index); 12473 ASSERT(storage->length() >= index);
12474 } 12474 }
12475 12475
12476 12476
12477 void StringDictionary::CopyEnumKeysTo(FixedArray* storage) { 12477 FixedArray* StringDictionary::CopyEnumKeysTo(FixedArray* storage) {
12478 int length = storage->length(); 12478 int length = storage->length();
12479 ASSERT(length >= NumberOfEnumElements()); 12479 ASSERT(length >= NumberOfEnumElements());
12480 Heap* heap = GetHeap(); 12480 Heap* heap = GetHeap();
12481 Object* undefined_value = heap->undefined_value(); 12481 Object* undefined_value = heap->undefined_value();
12482 int capacity = Capacity(); 12482 int capacity = Capacity();
12483 int properties = 0; 12483 int properties = 0;
12484 12484
12485 // Fill in the enumeration array by assigning enumerable keys at their 12485 // Fill in the enumeration array by assigning enumerable keys at their
12486 // enumeration index. This will leave holes in the array if there are keys 12486 // enumeration index. This will leave holes in the array if there are keys
12487 // that are deleted or not enumerable. 12487 // that are deleted or not enumerable.
12488 for (int i = 0; i < capacity; i++) { 12488 for (int i = 0; i < capacity; i++) {
12489 Object* k = KeyAt(i); 12489 Object* k = KeyAt(i);
12490 if (IsKey(k)) { 12490 if (IsKey(k)) {
12491 PropertyDetails details = DetailsAt(i); 12491 PropertyDetails details = DetailsAt(i);
12492 if (details.IsDeleted() || details.IsDontEnum()) continue; 12492 if (details.IsDeleted() || details.IsDontEnum()) continue;
12493 properties++; 12493 properties++;
12494 storage->set(details.dictionary_index() - 1, k); 12494 storage->set(details.dictionary_index() - 1, k);
12495 if (properties == length) break; 12495 if (properties == length) break;
12496 } 12496 }
12497 } 12497 }
12498 12498
12499 // There are holes in the enumeration array if less properties were assigned 12499 // There are holes in the enumeration array if less properties were assigned
12500 // than the length of the array. If so, crunch all the existing properties 12500 // than the length of the array. If so, crunch all the existing properties
12501 // together by shifting them to the left (maintaining the enumeration order), 12501 // together by shifting them to the left (maintaining the enumeration order),
12502 // and trimming of the right side of the array. 12502 // and trimming of the right side of the array.
12503 if (properties < length) { 12503 if (properties < length) {
12504 if (properties == 0) return heap->empty_fixed_array();
12504 properties = 0; 12505 properties = 0;
12505 for (int i = 0; i < length; ++i) { 12506 for (int i = 0; i < length; ++i) {
12506 Object* value = storage->get(i); 12507 Object* value = storage->get(i);
12507 if (value != undefined_value) { 12508 if (value != undefined_value) {
12508 storage->set(properties, value); 12509 storage->set(properties, value);
12509 ++properties; 12510 ++properties;
12510 } 12511 }
12511 } 12512 }
12512 RightTrimFixedArray<FROM_MUTATOR>(heap, storage, length - properties); 12513 RightTrimFixedArray<FROM_MUTATOR>(heap, storage, length - properties);
12513 } 12514 }
12515 return storage;
12514 } 12516 }
12515 12517
12516 12518
12517 template<typename Shape, typename Key> 12519 template<typename Shape, typename Key>
12518 void Dictionary<Shape, Key>::CopyKeysTo( 12520 void Dictionary<Shape, Key>::CopyKeysTo(
12519 FixedArray* storage, 12521 FixedArray* storage,
12520 int index, 12522 int index,
12521 typename Dictionary<Shape, Key>::SortMode sort_mode) { 12523 typename Dictionary<Shape, Key>::SortMode sort_mode) {
12522 ASSERT(storage->length() >= NumberOfElementsFilterAttributes( 12524 ASSERT(storage->length() >= NumberOfElementsFilterAttributes(
12523 static_cast<PropertyAttributes>(NONE))); 12525 static_cast<PropertyAttributes>(NONE)));
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
13197 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13199 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13198 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13200 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13199 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13201 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13200 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13202 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13201 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13203 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13202 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13204 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13203 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13205 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13204 } 13206 }
13205 13207
13206 } } // namespace v8::internal 13208 } } // namespace v8::internal
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