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

Side by Side Diff: src/factory.cc

Issue 10692185: Couple the enumeration index of a property to the size of the descriptor array where it first appea… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use the enumeration index of the LastAdded descriptor for appending. Created 8 years, 5 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/bootstrapper.cc ('k') | 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 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 isolate()->heap()->CopyCode(*code, reloc_info), 886 isolate()->heap()->CopyCode(*code, reloc_info),
887 Code); 887 Code);
888 } 888 }
889 889
890 890
891 MUST_USE_RESULT static inline MaybeObject* DoCopyAdd( 891 MUST_USE_RESULT static inline MaybeObject* DoCopyAdd(
892 DescriptorArray* array, 892 DescriptorArray* array,
893 String* key, 893 String* key,
894 Object* value, 894 Object* value,
895 PropertyAttributes attributes) { 895 PropertyAttributes attributes) {
896 CallbacksDescriptor desc(key, value, attributes, 0); 896 CallbacksDescriptor desc(key, value, attributes);
897 MaybeObject* obj = array->CopyAdd(&desc); 897 MaybeObject* obj = array->CopyAdd(&desc);
898 return obj; 898 return obj;
899 } 899 }
900 900
901 901
902 // Allocate the new array. 902 // Allocate the new array.
903 Handle<DescriptorArray> Factory::CopyAppendForeignDescriptor( 903 Handle<DescriptorArray> Factory::CopyAppendForeignDescriptor(
904 Handle<DescriptorArray> array, 904 Handle<DescriptorArray> array,
905 Handle<String> key, 905 Handle<String> key,
906 Handle<Object> value, 906 Handle<Object> value,
(...skipping 16 matching lines...) Expand all
923 v8::NeanderArray callbacks(descriptors); 923 v8::NeanderArray callbacks(descriptors);
924 int nof_callbacks = callbacks.length(); 924 int nof_callbacks = callbacks.length();
925 int descriptor_count = array->number_of_descriptors(); 925 int descriptor_count = array->number_of_descriptors();
926 Handle<DescriptorArray> result = 926 Handle<DescriptorArray> result =
927 NewDescriptorArray(descriptor_count + nof_callbacks); 927 NewDescriptorArray(descriptor_count + nof_callbacks);
928 928
929 // Ensure that marking will not progress and change color of objects. 929 // Ensure that marking will not progress and change color of objects.
930 DescriptorArray::WhitenessWitness witness(*result); 930 DescriptorArray::WhitenessWitness witness(*result);
931 931
932 // Copy the descriptors from the array. 932 // Copy the descriptors from the array.
933 for (int i = 0; i < descriptor_count; i++) { 933 if (0 < descriptor_count) {
934 DescriptorArray::CopyFrom(result, i, array, i, witness); 934 result->SetLastAdded(array->LastAdded());
935 for (int i = 0; i < descriptor_count; i++) {
936 DescriptorArray::CopyFrom(result, i, array, i, witness);
937 }
935 } 938 }
936 939
937 // Fill in new callback descriptors. Process the callbacks from 940 // Fill in new callback descriptors. Process the callbacks from
938 // back to front so that the last callback with a given name takes 941 // back to front so that the last callback with a given name takes
939 // precedence over previously added callbacks with that name. 942 // precedence over previously added callbacks with that name.
940 int added_descriptor_count = descriptor_count;
941 int next_enum = array->NextEnumerationIndex();
942 for (int i = nof_callbacks - 1; i >= 0; i--) { 943 for (int i = nof_callbacks - 1; i >= 0; i--) {
943 Handle<AccessorInfo> entry = 944 Handle<AccessorInfo> entry =
944 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); 945 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i)));
945 // Ensure the key is a symbol before writing into the instance descriptor. 946 // Ensure the key is a symbol before writing into the instance descriptor.
946 Handle<String> key = 947 Handle<String> key =
947 SymbolFromString(Handle<String>(String::cast(entry->name()))); 948 SymbolFromString(Handle<String>(String::cast(entry->name())));
948 // Check if a descriptor with this name already exists before writing. 949 // Check if a descriptor with this name already exists before writing.
949 if (LinearSearch(*result, EXPECT_UNSORTED, *key, added_descriptor_count) == 950 if (LinearSearch(*result,
951 EXPECT_UNSORTED,
952 *key,
953 result->NumberOfSetDescriptors()) ==
950 DescriptorArray::kNotFound) { 954 DescriptorArray::kNotFound) {
951 CallbacksDescriptor desc(*key, 955 CallbacksDescriptor desc(*key, *entry, entry->property_attributes());
952 *entry, 956 result->Append(&desc, witness);
953 entry->property_attributes(),
954 next_enum++);
955 result->Set(added_descriptor_count, &desc, witness);
956 added_descriptor_count++;
957 } 957 }
958 } 958 }
959 959
960 int new_number_of_descriptors = result->NumberOfSetDescriptors();
960 // Return the old descriptor array if there were no new elements. 961 // Return the old descriptor array if there were no new elements.
961 if (added_descriptor_count == descriptor_count) return array; 962 if (new_number_of_descriptors == descriptor_count) return array;
962 963
963 // If duplicates were detected, allocate a result of the right size 964 // If duplicates were detected, allocate a result of the right size
964 // and transfer the elements. 965 // and transfer the elements.
965 if (added_descriptor_count < result->length()) { 966 if (new_number_of_descriptors < result->length()) {
966 Handle<DescriptorArray> new_result = 967 Handle<DescriptorArray> new_result =
967 NewDescriptorArray(added_descriptor_count); 968 NewDescriptorArray(new_number_of_descriptors);
968 for (int i = 0; i < added_descriptor_count; i++) { 969 for (int i = 0; i < new_number_of_descriptors; i++) {
969 DescriptorArray::CopyFrom(new_result, i, result, i, witness); 970 DescriptorArray::CopyFrom(new_result, i, result, i, witness);
970 } 971 }
971 result = new_result; 972 result = new_result;
972 } 973 }
973 974
974 // Sort the result before returning. 975 // Sort the result before returning.
975 result->Sort(witness); 976 result->Sort(witness);
976 ASSERT(result->NextEnumerationIndex() == next_enum);
977 return result; 977 return result;
978 } 978 }
979 979
980 980
981 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, 981 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
982 PretenureFlag pretenure) { 982 PretenureFlag pretenure) {
983 CALL_HEAP_FUNCTION( 983 CALL_HEAP_FUNCTION(
984 isolate(), 984 isolate(),
985 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); 985 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject);
986 } 986 }
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 1492
1493 1493
1494 Handle<Object> Factory::ToBoolean(bool value) { 1494 Handle<Object> Factory::ToBoolean(bool value) {
1495 return Handle<Object>(value 1495 return Handle<Object>(value
1496 ? isolate()->heap()->true_value() 1496 ? isolate()->heap()->true_value()
1497 : isolate()->heap()->false_value()); 1497 : isolate()->heap()->false_value());
1498 } 1498 }
1499 1499
1500 1500
1501 } } // namespace v8::internal 1501 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698