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

Side by Side Diff: src/handles.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 | « 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 // 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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 DescriptorArray* desc = object->map()->instance_descriptors(); 764 DescriptorArray* desc = object->map()->instance_descriptors();
765 desc->SetEnumCache(*bridge_storage, 765 desc->SetEnumCache(*bridge_storage,
766 *storage, 766 *storage,
767 indices.is_null() ? Object::cast(Smi::FromInt(0)) 767 indices.is_null() ? Object::cast(Smi::FromInt(0))
768 : Object::cast(*indices)); 768 : Object::cast(*indices));
769 if (cache_result) { 769 if (cache_result) {
770 object->map()->SetEnumLength(index); 770 object->map()->SetEnumLength(index);
771 } 771 }
772 return storage; 772 return storage;
773 } else { 773 } else {
774 int num_enum = object->NumberOfLocalProperties(DONT_ENUM); 774 Handle<StringDictionary> dictionary(object->property_dictionary());
775 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); 775
776 Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum); 776 int length = dictionary->NumberOfElements();
777 object->property_dictionary()->CopyEnumKeysTo(*storage, *sort_array); 777 if (length == 0) {
778 return Handle<FixedArray>(isolate->heap()->empty_fixed_array());
779 }
780
781 // The enumeration array is generated by allocating an array big enough to
782 // hold all properties that have been seen, whether they are are deleted or
783 // not. Subsequently all visible properties are added to the array. If some
784 // properties were not visible, the array is trimmed so it only contains
785 // visible properties. This improves over adding elements and sorting by
786 // index by having linear complexity rather than n*log(n).
787
788 // By comparing the monotonous NextEnumerationIndex to the NumberOfElements,
789 // we can predict the number of holes in the final array. If there will be
790 // more than 50% holes, regenerate the enumeration indices to reduce the
791 // number of holes to a minimum. This avoids allocating a large array if
792 // many properties were added but subsequently deleted.
793 int next_enumeration = dictionary->NextEnumerationIndex();
794 if (next_enumeration > (length * 3) / 2) {
795 StringDictionary::DoGenerateNewEnumerationIndices(dictionary);
796 next_enumeration = dictionary->NextEnumerationIndex();
797 }
798
799 Handle<FixedArray> storage =
800 isolate->factory()->NewFixedArray(next_enumeration);
801
802 dictionary->CopyEnumKeysTo(*storage);
803 ASSERT(storage->length() == object->NumberOfLocalProperties(DONT_ENUM));
778 return storage; 804 return storage;
779 } 805 }
780 } 806 }
781 807
782 808
783 Handle<ObjectHashSet> ObjectHashSetAdd(Handle<ObjectHashSet> table, 809 Handle<ObjectHashSet> ObjectHashSetAdd(Handle<ObjectHashSet> table,
784 Handle<Object> key) { 810 Handle<Object> key) {
785 CALL_HEAP_FUNCTION(table->GetIsolate(), 811 CALL_HEAP_FUNCTION(table->GetIsolate(),
786 table->Add(*key), 812 table->Add(*key),
787 ObjectHashSet); 813 ObjectHashSet);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 data->next = prev_next_; 1026 data->next = prev_next_;
1001 data->limit = prev_limit_; 1027 data->limit = prev_limit_;
1002 #ifdef DEBUG 1028 #ifdef DEBUG
1003 handles_detached_ = true; 1029 handles_detached_ = true;
1004 #endif 1030 #endif
1005 return deferred; 1031 return deferred;
1006 } 1032 }
1007 1033
1008 1034
1009 } } // namespace v8::internal 1035 } } // namespace v8::internal
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