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

Side by Side Diff: src/objects.cc

Issue 250013002: Dictionary::GenerateNewEnumerationIndices() and Dictionary::EnsureCapacity() handlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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') | src/objects-inl.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 14787 matching lines...) Expand 10 before | Expand all | Expand 10 after
14798 } 14798 }
14799 14799
14800 14800
14801 template<typename Derived, typename Shape, typename Key> 14801 template<typename Derived, typename Shape, typename Key>
14802 Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity( 14802 Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(
14803 Handle<Derived> table, 14803 Handle<Derived> table,
14804 int n, 14804 int n,
14805 Key key, 14805 Key key,
14806 PretenureFlag pretenure) { 14806 PretenureFlag pretenure) {
14807 Isolate* isolate = table->GetIsolate(); 14807 Isolate* isolate = table->GetIsolate();
14808 CALL_HEAP_FUNCTION(isolate, 14808 CALL_HEAP_FUNCTION(
14809 table->EnsureCapacity(n, key, pretenure), 14809 isolate,
14810 Derived); 14810 static_cast<HashTable*>(*table)->EnsureCapacity(n, key, pretenure),
14811 Derived);
14811 } 14812 }
14812 14813
14813 14814
14814 template<typename Derived, typename Shape, typename Key> 14815 template<typename Derived, typename Shape, typename Key>
14815 Handle<Derived> HashTable<Derived, Shape, Key>::Shrink(Handle<Derived> table, 14816 Handle<Derived> HashTable<Derived, Shape, Key>::Shrink(Handle<Derived> table,
14816 Key key) { 14817 Key key) {
14817 int capacity = table->Capacity(); 14818 int capacity = table->Capacity();
14818 int nof = table->NumberOfElements(); 14819 int nof = table->NumberOfElements();
14819 14820
14820 // Shrink to fit the number of elements if only a quarter of the 14821 // Shrink to fit the number of elements if only a quarter of the
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
14970 Dictionary<NameDictionary, NameDictionaryShape, Name*>::SortMode); 14971 Dictionary<NameDictionary, NameDictionaryShape, Name*>::SortMode);
14971 14972
14972 template int 14973 template int
14973 Dictionary<NameDictionary, NameDictionaryShape, Name*>:: 14974 Dictionary<NameDictionary, NameDictionaryShape, Name*>::
14974 NumberOfElementsFilterAttributes(PropertyAttributes); 14975 NumberOfElementsFilterAttributes(PropertyAttributes);
14975 14976
14976 template Handle<NameDictionary> 14977 template Handle<NameDictionary>
14977 Dictionary<NameDictionary, NameDictionaryShape, Name*>::Add( 14978 Dictionary<NameDictionary, NameDictionaryShape, Name*>::Add(
14978 Handle<NameDictionary>, Name*, Handle<Object>, PropertyDetails); 14979 Handle<NameDictionary>, Name*, Handle<Object>, PropertyDetails);
14979 14980
14980 template MaybeObject* 14981 template void
14981 Dictionary<NameDictionary, NameDictionaryShape, Name*>:: 14982 Dictionary<NameDictionary, NameDictionaryShape, Name*>::
14982 GenerateNewEnumerationIndices(); 14983 GenerateNewEnumerationIndices(Handle<NameDictionary>);
14983 14984
14984 template int 14985 template int
14985 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: 14986 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
14986 NumberOfElementsFilterAttributes(PropertyAttributes); 14987 NumberOfElementsFilterAttributes(PropertyAttributes);
14987 14988
14988 template Handle<SeededNumberDictionary> 14989 template Handle<SeededNumberDictionary>
14989 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: 14990 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
14990 Add(Handle<SeededNumberDictionary>, 14991 Add(Handle<SeededNumberDictionary>,
14991 uint32_t, 14992 uint32_t,
14992 Handle<Object>, 14993 Handle<Object>,
14993 PropertyDetails); 14994 PropertyDetails);
14994 14995
14995 template Handle<UnseededNumberDictionary> 14996 template Handle<UnseededNumberDictionary>
14996 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>:: 14997 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
14997 Add(Handle<UnseededNumberDictionary>, 14998 Add(Handle<UnseededNumberDictionary>,
14998 uint32_t, 14999 uint32_t,
14999 Handle<Object>, 15000 Handle<Object>,
15000 PropertyDetails); 15001 PropertyDetails);
15001 15002
15002 template MaybeObject* 15003 template Handle<SeededNumberDictionary>
15003 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: 15004 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
15004 EnsureCapacity(int, uint32_t); 15005 EnsureCapacity(Handle<SeededNumberDictionary>, int, uint32_t);
15005 15006
15006 template MaybeObject* 15007 template Handle<UnseededNumberDictionary>
15007 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>:: 15008 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
15008 EnsureCapacity(int, uint32_t); 15009 EnsureCapacity(Handle<UnseededNumberDictionary>, int, uint32_t);
15009 15010
15010 template MaybeObject* 15011 template Handle<NameDictionary>
15011 Dictionary<NameDictionary, NameDictionaryShape, Name*>:: 15012 Dictionary<NameDictionary, NameDictionaryShape, Name*>::
15012 EnsureCapacity(int, Name*); 15013 EnsureCapacity(Handle<NameDictionary>, int, Name*);
15013 15014
15014 template MaybeObject* 15015 template MaybeObject*
15015 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: 15016 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
15016 AddEntry(uint32_t, Object*, PropertyDetails, uint32_t); 15017 AddEntry(uint32_t, Object*, PropertyDetails, uint32_t);
15017 15018
15018 template MaybeObject* 15019 template MaybeObject*
15019 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>:: 15020 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
15020 AddEntry(uint32_t, Object*, PropertyDetails, uint32_t); 15021 AddEntry(uint32_t, Object*, PropertyDetails, uint32_t);
15021 15022
15022 template MaybeObject* 15023 template MaybeObject*
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
15805 at_least_space_for, 15806 at_least_space_for,
15806 USE_DEFAULT_MINIMUM_CAPACITY, 15807 USE_DEFAULT_MINIMUM_CAPACITY,
15807 pretenure); 15808 pretenure);
15808 15809
15809 // Initialize the next enumeration index. 15810 // Initialize the next enumeration index.
15810 dict->SetNextEnumerationIndex(PropertyDetails::kInitialIndex); 15811 dict->SetNextEnumerationIndex(PropertyDetails::kInitialIndex);
15811 return dict; 15812 return dict;
15812 } 15813 }
15813 15814
15814 15815
15815
15816 void NameDictionary::DoGenerateNewEnumerationIndices(
15817 Handle<NameDictionary> dictionary) {
15818 CALL_HEAP_FUNCTION_VOID(dictionary->GetIsolate(),
15819 dictionary->GenerateNewEnumerationIndices());
15820 }
15821
15822 template<typename Derived, typename Shape, typename Key> 15816 template<typename Derived, typename Shape, typename Key>
15823 MaybeObject* Dictionary<Derived, Shape, Key>::GenerateNewEnumerationIndices() { 15817 void Dictionary<Derived, Shape, Key>::GenerateNewEnumerationIndices(
15824 Heap* heap = Dictionary::GetHeap(); 15818 Handle<Derived> dictionary) {
15825 int length = DerivedHashTable::NumberOfElements(); 15819 Factory* factory = dictionary->GetIsolate()->factory();
15820 int length = dictionary->NumberOfElements();
15826 15821
15827 // Allocate and initialize iteration order array. 15822 // Allocate and initialize iteration order array.
15828 Object* obj; 15823 Handle<FixedArray> iteration_order = factory->NewFixedArray(length);
15829 { MaybeObject* maybe_obj = heap->AllocateFixedArray(length);
15830 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
15831 }
15832 FixedArray* iteration_order = FixedArray::cast(obj);
15833 for (int i = 0; i < length; i++) { 15824 for (int i = 0; i < length; i++) {
15834 iteration_order->set(i, Smi::FromInt(i)); 15825 iteration_order->set(i, Smi::FromInt(i));
15835 } 15826 }
15836 15827
15837 // Allocate array with enumeration order. 15828 // Allocate array with enumeration order.
15838 { MaybeObject* maybe_obj = heap->AllocateFixedArray(length); 15829 Handle<FixedArray> enumeration_order = factory->NewFixedArray(length);
15839 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
15840 }
15841 FixedArray* enumeration_order = FixedArray::cast(obj);
15842 15830
15843 // Fill the enumeration order array with property details. 15831 // Fill the enumeration order array with property details.
15844 int capacity = DerivedHashTable::Capacity(); 15832 int capacity = dictionary->Capacity();
15845 int pos = 0; 15833 int pos = 0;
15846 for (int i = 0; i < capacity; i++) { 15834 for (int i = 0; i < capacity; i++) {
15847 if (Dictionary::IsKey(Dictionary::KeyAt(i))) { 15835 if (dictionary->IsKey(dictionary->KeyAt(i))) {
15848 int index = DetailsAt(i).dictionary_index(); 15836 int index = dictionary->DetailsAt(i).dictionary_index();
15849 enumeration_order->set(pos++, Smi::FromInt(index)); 15837 enumeration_order->set(pos++, Smi::FromInt(index));
15850 } 15838 }
15851 } 15839 }
15852 15840
15853 // Sort the arrays wrt. enumeration order. 15841 // Sort the arrays wrt. enumeration order.
15854 iteration_order->SortPairs(enumeration_order, enumeration_order->length()); 15842 iteration_order->SortPairs(*enumeration_order, enumeration_order->length());
15855 15843
15856 // Overwrite the enumeration_order with the enumeration indices. 15844 // Overwrite the enumeration_order with the enumeration indices.
15857 for (int i = 0; i < length; i++) { 15845 for (int i = 0; i < length; i++) {
15858 int index = Smi::cast(iteration_order->get(i))->value(); 15846 int index = Smi::cast(iteration_order->get(i))->value();
15859 int enum_index = PropertyDetails::kInitialIndex + i; 15847 int enum_index = PropertyDetails::kInitialIndex + i;
15860 enumeration_order->set(index, Smi::FromInt(enum_index)); 15848 enumeration_order->set(index, Smi::FromInt(enum_index));
15861 } 15849 }
15862 15850
15863 // Update the dictionary with new indices. 15851 // Update the dictionary with new indices.
15864 capacity = DerivedHashTable::Capacity(); 15852 capacity = dictionary->Capacity();
15865 pos = 0; 15853 pos = 0;
15866 for (int i = 0; i < capacity; i++) { 15854 for (int i = 0; i < capacity; i++) {
15867 if (Dictionary::IsKey(Dictionary::KeyAt(i))) { 15855 if (dictionary->IsKey(dictionary->KeyAt(i))) {
15868 int enum_index = Smi::cast(enumeration_order->get(pos++))->value(); 15856 int enum_index = Smi::cast(enumeration_order->get(pos++))->value();
15869 PropertyDetails details = DetailsAt(i); 15857 PropertyDetails details = dictionary->DetailsAt(i);
15870 PropertyDetails new_details = PropertyDetails( 15858 PropertyDetails new_details = PropertyDetails(
15871 details.attributes(), details.type(), enum_index); 15859 details.attributes(), details.type(), enum_index);
15872 DetailsAtPut(i, new_details); 15860 dictionary->DetailsAtPut(i, new_details);
15873 } 15861 }
15874 } 15862 }
15875 15863
15876 // Set the next enumeration index. 15864 // Set the next enumeration index.
15877 SetNextEnumerationIndex(PropertyDetails::kInitialIndex+length); 15865 dictionary->SetNextEnumerationIndex(PropertyDetails::kInitialIndex+length);
15878 return this;
15879 } 15866 }
15880 15867
15881 template<typename Derived, typename Shape, typename Key>
15882 MaybeObject* Dictionary<Derived, Shape, Key>::EnsureCapacity(int n, Key key) {
15883 // Check whether there are enough enumeration indices to add n elements.
15884 if (Shape::kIsEnumerable &&
15885 !PropertyDetails::IsValidIndex(NextEnumerationIndex() + n)) {
15886 // If not, we generate new indices for the properties.
15887 Object* result;
15888 { MaybeObject* maybe_result = GenerateNewEnumerationIndices();
15889 if (!maybe_result->ToObject(&result)) return maybe_result;
15890 }
15891 }
15892 return DerivedHashTable::EnsureCapacity(n, key);
15893 }
15894
15895
15896 15868
15897 template<typename Derived, typename Shape, typename Key> 15869 template<typename Derived, typename Shape, typename Key>
15898 Handle<Derived> Dictionary<Derived, Shape, Key>::EnsureCapacity( 15870 Handle<Derived> Dictionary<Derived, Shape, Key>::EnsureCapacity(
15899 Handle<Derived> obj, int n, Key key) { 15871 Handle<Derived> dictionary, int n, Key key) {
15900 Isolate* isolate = obj->GetIsolate(); 15872 // Check whether there are enough enumeration indices to add n elements.
15901 CALL_HEAP_FUNCTION(isolate, 15873 if (Shape::kIsEnumerable &&
15902 obj->EnsureCapacity(n, key), 15874 !PropertyDetails::IsValidIndex(dictionary->NextEnumerationIndex() + n)) {
15903 Derived); 15875 // If not, we generate new indices for the properties.
15876 GenerateNewEnumerationIndices(dictionary);
15877 }
15878 return DerivedHashTable::EnsureCapacity(dictionary, n, key);
15904 } 15879 }
15905 15880
15906 15881
15907 // TODO(ishell): Temporary wrapper until handlified. 15882 // TODO(ishell): Temporary wrapper until handlified.
15908 template<typename Derived, typename Shape, typename Key> 15883 template<typename Derived, typename Shape, typename Key>
15909 Handle<Object> Dictionary<Derived, Shape, Key>::DeleteProperty( 15884 Handle<Object> Dictionary<Derived, Shape, Key>::DeleteProperty(
15910 Handle<Dictionary<Derived, Shape, Key> > dictionary, 15885 Handle<Dictionary<Derived, Shape, Key> > dictionary,
15911 int entry, 15886 int entry,
15912 JSObject::DeleteMode mode) { 15887 JSObject::DeleteMode mode) {
15913 CALL_HEAP_FUNCTION(dictionary->GetIsolate(), 15888 CALL_HEAP_FUNCTION(dictionary->GetIsolate(),
(...skipping 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after
17410 #define ERROR_MESSAGES_TEXTS(C, T) T, 17385 #define ERROR_MESSAGES_TEXTS(C, T) T,
17411 static const char* error_messages_[] = { 17386 static const char* error_messages_[] = {
17412 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 17387 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
17413 }; 17388 };
17414 #undef ERROR_MESSAGES_TEXTS 17389 #undef ERROR_MESSAGES_TEXTS
17415 return error_messages_[reason]; 17390 return error_messages_[reason];
17416 } 17391 }
17417 17392
17418 17393
17419 } } // namespace v8::internal 17394 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698