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

Side by Side Diff: src/handles.cc

Issue 198943002: Simplify GetEnumPropertyKeys and avoid trimming fixed arrays in large object space. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix filter Created 6 years, 9 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 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 *storage, 705 *storage,
706 indices.is_null() ? Object::cast(Smi::FromInt(0)) 706 indices.is_null() ? Object::cast(Smi::FromInt(0))
707 : Object::cast(*indices)); 707 : Object::cast(*indices));
708 if (cache_result) { 708 if (cache_result) {
709 object->map()->SetEnumLength(enum_size); 709 object->map()->SetEnumLength(enum_size);
710 } 710 }
711 711
712 return ReduceFixedArrayTo(storage, enum_size); 712 return ReduceFixedArrayTo(storage, enum_size);
713 } else { 713 } else {
714 Handle<NameDictionary> dictionary(object->property_dictionary()); 714 Handle<NameDictionary> dictionary(object->property_dictionary());
715 715 int length = dictionary->NumberOfEnumElements();
716 int length = dictionary->NumberOfElements();
717 if (length == 0) { 716 if (length == 0) {
718 return Handle<FixedArray>(isolate->heap()->empty_fixed_array()); 717 return Handle<FixedArray>(isolate->heap()->empty_fixed_array());
719 } 718 }
720 719 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(length);
721 // The enumeration array is generated by allocating an array big enough to 720 dictionary->CopyEnumKeysTo(*storage);
722 // hold all properties that have been seen, whether they are are deleted or
723 // not. Subsequently all visible properties are added to the array. If some
724 // properties were not visible, the array is trimmed so it only contains
725 // visible properties. This improves over adding elements and sorting by
726 // index by having linear complexity rather than n*log(n).
727
728 // By comparing the monotonous NextEnumerationIndex to the NumberOfElements,
729 // we can predict the number of holes in the final array. If there will be
730 // more than 50% holes, regenerate the enumeration indices to reduce the
731 // number of holes to a minimum. This avoids allocating a large array if
732 // many properties were added but subsequently deleted.
733 int next_enumeration = dictionary->NextEnumerationIndex();
734 if (!object->IsGlobalObject() && next_enumeration > (length * 3) / 2) {
735 NameDictionary::DoGenerateNewEnumerationIndices(dictionary);
736 next_enumeration = dictionary->NextEnumerationIndex();
737 }
738
739 Handle<FixedArray> storage =
740 isolate->factory()->NewFixedArray(next_enumeration);
741
742 storage = Handle<FixedArray>(dictionary->CopyEnumKeysTo(*storage));
743 ASSERT(storage->length() == object->NumberOfLocalProperties(DONT_SHOW));
744 return storage; 721 return storage;
745 } 722 }
746 } 723 }
747 724
748 725
749 DeferredHandleScope::DeferredHandleScope(Isolate* isolate) 726 DeferredHandleScope::DeferredHandleScope(Isolate* isolate)
750 : impl_(isolate->handle_scope_implementer()) { 727 : impl_(isolate->handle_scope_implementer()) {
751 impl_->BeginDeferredScope(); 728 impl_->BeginDeferredScope();
752 HandleScopeData* data = impl_->isolate()->handle_scope_data(); 729 HandleScopeData* data = impl_->isolate()->handle_scope_data();
753 Object** new_next = impl_->GetSpareOrNewBlock(); 730 Object** new_next = impl_->GetSpareOrNewBlock();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 Handle<Code> code) { 767 Handle<Code> code) {
791 heap->EnsureWeakObjectToCodeTable(); 768 heap->EnsureWeakObjectToCodeTable();
792 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object)); 769 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object));
793 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code); 770 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code);
794 CALL_HEAP_FUNCTION_VOID(heap->isolate(), 771 CALL_HEAP_FUNCTION_VOID(heap->isolate(),
795 heap->AddWeakObjectToCodeDependency(*object, *dep)); 772 heap->AddWeakObjectToCodeDependency(*object, *dep));
796 } 773 }
797 774
798 775
799 } } // namespace v8::internal 776 } } // 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