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

Side by Side Diff: src/objects.cc

Issue 10916076: Optimize dictionary enum generation. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Adding comments. 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 12132 matching lines...) Expand 10 before | Expand all | Expand 10 after
12143 HashTable<Shape, Key>::Allocate(at_least_space_for); 12143 HashTable<Shape, Key>::Allocate(at_least_space_for);
12144 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 12144 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
12145 } 12145 }
12146 // Initialize the next enumeration index. 12146 // Initialize the next enumeration index.
12147 Dictionary<Shape, Key>::cast(obj)-> 12147 Dictionary<Shape, Key>::cast(obj)->
12148 SetNextEnumerationIndex(PropertyDetails::kInitialIndex); 12148 SetNextEnumerationIndex(PropertyDetails::kInitialIndex);
12149 return obj; 12149 return obj;
12150 } 12150 }
12151 12151
12152 12152
12153 void StringDictionary::DoGenerateNewEnumerationIndices(
12154 Handle<StringDictionary> dictionary) {
12155 CALL_HEAP_FUNCTION_VOID(dictionary->GetIsolate(),
12156 dictionary->GenerateNewEnumerationIndices());
12157 }
12158
12153 template<typename Shape, typename Key> 12159 template<typename Shape, typename Key>
12154 MaybeObject* Dictionary<Shape, Key>::GenerateNewEnumerationIndices() { 12160 MaybeObject* Dictionary<Shape, Key>::GenerateNewEnumerationIndices() {
12155 Heap* heap = Dictionary<Shape, Key>::GetHeap(); 12161 Heap* heap = Dictionary<Shape, Key>::GetHeap();
12156 int length = HashTable<Shape, Key>::NumberOfElements(); 12162 int length = HashTable<Shape, Key>::NumberOfElements();
12157 12163
12158 // Allocate and initialize iteration order array. 12164 // Allocate and initialize iteration order array.
12159 Object* obj; 12165 Object* obj;
12160 { MaybeObject* maybe_obj = heap->AllocateFixedArray(length); 12166 { MaybeObject* maybe_obj = heap->AllocateFixedArray(length);
12161 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 12167 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
12162 } 12168 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
12461 if ((attr & filter) == 0) storage->set(index++, k); 12467 if ((attr & filter) == 0) storage->set(index++, k);
12462 } 12468 }
12463 } 12469 }
12464 if (sort_mode == Dictionary<Shape, Key>::SORTED) { 12470 if (sort_mode == Dictionary<Shape, Key>::SORTED) {
12465 storage->SortPairs(storage, index); 12471 storage->SortPairs(storage, index);
12466 } 12472 }
12467 ASSERT(storage->length() >= index); 12473 ASSERT(storage->length() >= index);
12468 } 12474 }
12469 12475
12470 12476
12471 void StringDictionary::CopyEnumKeysTo(FixedArray* storage, 12477 void StringDictionary::CopyEnumKeysTo(FixedArray* storage) {
12472 FixedArray* sort_array) { 12478 int length = storage->length();
12473 ASSERT(storage->length() >= NumberOfEnumElements()); 12479 ASSERT(length >= NumberOfEnumElements());
12480 Heap* heap = GetHeap();
12481 Object* undefined_value = heap->undefined_value();
12474 int capacity = Capacity(); 12482 int capacity = Capacity();
12475 int index = 0; 12483 int properties = 0;
12484
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
12487 // that are deleted or not enumerable.
12476 for (int i = 0; i < capacity; i++) { 12488 for (int i = 0; i < capacity; i++) {
12477 Object* k = KeyAt(i); 12489 Object* k = KeyAt(i);
12478 if (IsKey(k)) { 12490 if (IsKey(k)) {
12479 PropertyDetails details = DetailsAt(i); 12491 PropertyDetails details = DetailsAt(i);
12480 if (details.IsDeleted() || details.IsDontEnum()) continue; 12492 if (details.IsDeleted() || details.IsDontEnum()) continue;
12481 storage->set(index, k); 12493 properties++;
12482 sort_array->set(index, Smi::FromInt(details.dictionary_index())); 12494 storage->set(details.dictionary_index() - 1, k);
12483 index++; 12495 if (properties == length) break;
12484 } 12496 }
12485 } 12497 }
12486 storage->SortPairs(sort_array, sort_array->length()); 12498
12487 ASSERT(storage->length() >= index); 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
12501 // together by shifting them to the left (maintaining the enumeration order),
12502 // and trimming of the right side of the array.
12503 if (properties < length) {
12504 properties = 0;
12505 for (int i = 0; i < length; ++i) {
12506 Object* value = storage->get(i);
12507 if (value != undefined_value) {
12508 storage->set(properties, value);
12509 ++properties;
12510 }
12511 }
12512 RightTrimFixedArray<FROM_MUTATOR>(heap, storage, length - properties);
12513 }
12488 } 12514 }
12489 12515
12490 12516
12491 template<typename Shape, typename Key> 12517 template<typename Shape, typename Key>
12492 void Dictionary<Shape, Key>::CopyKeysTo( 12518 void Dictionary<Shape, Key>::CopyKeysTo(
12493 FixedArray* storage, 12519 FixedArray* storage,
12494 int index, 12520 int index,
12495 typename Dictionary<Shape, Key>::SortMode sort_mode) { 12521 typename Dictionary<Shape, Key>::SortMode sort_mode) {
12496 ASSERT(storage->length() >= NumberOfElementsFilterAttributes( 12522 ASSERT(storage->length() >= NumberOfElementsFilterAttributes(
12497 static_cast<PropertyAttributes>(NONE))); 12523 static_cast<PropertyAttributes>(NONE)));
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
13171 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13197 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13172 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13198 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13173 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13199 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13174 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13200 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13175 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13201 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13176 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13202 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13177 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13203 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13178 } 13204 }
13179 13205
13180 } } // namespace v8::internal 13206 } } // 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