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

Side by Side Diff: src/factory.cc

Issue 10802034: Moved lastadded from DescriptorArray to Map. Renamed kLastAdded to kEnumCache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments. 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/arm/macro-assembler-arm.cc ('k') | src/heap.cc » ('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 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 int nof_callbacks = callbacks.length(); 899 int nof_callbacks = callbacks.length();
900 int descriptor_count = array->number_of_descriptors(); 900 int descriptor_count = array->number_of_descriptors();
901 Handle<DescriptorArray> result = 901 Handle<DescriptorArray> result =
902 NewDescriptorArray(descriptor_count + nof_callbacks); 902 NewDescriptorArray(descriptor_count + nof_callbacks);
903 903
904 // Ensure that marking will not progress and change color of objects. 904 // Ensure that marking will not progress and change color of objects.
905 DescriptorArray::WhitenessWitness witness(*result); 905 DescriptorArray::WhitenessWitness witness(*result);
906 906
907 // Copy the descriptors from the array. 907 // Copy the descriptors from the array.
908 if (0 < descriptor_count) { 908 if (0 < descriptor_count) {
909 result->SetLastAdded(array->LastAdded());
910 for (int i = 0; i < descriptor_count; i++) { 909 for (int i = 0; i < descriptor_count; i++) {
911 result->CopyFrom(i, *array, i, witness); 910 result->CopyFrom(i, *array, i, witness);
912 } 911 }
913 } 912 }
914 913
915 map->set_instance_descriptors(*result); 914 map->set_instance_descriptors(*result);
916 915
917 // Fill in new callback descriptors. Process the callbacks from 916 // Fill in new callback descriptors. Process the callbacks from
918 // back to front so that the last callback with a given name takes 917 // back to front so that the last callback with a given name takes
919 // precedence over previously added callbacks with that name. 918 // precedence over previously added callbacks with that name.
920 for (int i = nof_callbacks - 1; i >= 0; i--) { 919 for (int i = nof_callbacks - 1; i >= 0; i--) {
921 Handle<AccessorInfo> entry = 920 Handle<AccessorInfo> entry =
922 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); 921 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i)));
923 // Ensure the key is a symbol before writing into the instance descriptor. 922 // Ensure the key is a symbol before writing into the instance descriptor.
924 Handle<String> key = 923 Handle<String> key =
925 SymbolFromString(Handle<String>(String::cast(entry->name()))); 924 SymbolFromString(Handle<String>(String::cast(entry->name())));
926 // Check if a descriptor with this name already exists before writing. 925 // Check if a descriptor with this name already exists before writing.
927 if (LinearSearch(*result, *key, result->NumberOfSetDescriptors()) == 926 if (LinearSearch(*result, *key, map->NumberOfSetDescriptors()) ==
928 DescriptorArray::kNotFound) { 927 DescriptorArray::kNotFound) {
929 CallbacksDescriptor desc(*key, *entry, entry->property_attributes()); 928 CallbacksDescriptor desc(*key, *entry, entry->property_attributes());
930 map->AppendDescriptor(&desc, witness); 929 map->AppendDescriptor(&desc, witness);
931 } 930 }
932 } 931 }
933 932
934 int new_number_of_descriptors = result->NumberOfSetDescriptors(); 933 int new_number_of_descriptors = map->NumberOfSetDescriptors();
935 // Reinstall the original descriptor array if no new elements were added. 934 // Reinstall the original descriptor array if no new elements were added.
936 if (new_number_of_descriptors == descriptor_count) { 935 if (new_number_of_descriptors == descriptor_count) {
937 map->set_instance_descriptors(*array); 936 map->set_instance_descriptors(*array);
938 return; 937 return;
939 } 938 }
940 939
941 // If duplicates were detected, allocate a result of the right size 940 // If duplicates were detected, allocate a result of the right size
942 // and transfer the elements. 941 // and transfer the elements.
943 if (new_number_of_descriptors < result->length()) { 942 if (new_number_of_descriptors < result->length()) {
944 Handle<DescriptorArray> new_result = 943 Handle<DescriptorArray> new_result =
945 NewDescriptorArray(new_number_of_descriptors); 944 NewDescriptorArray(new_number_of_descriptors);
946 for (int i = 0; i < new_number_of_descriptors; i++) { 945 for (int i = 0; i < new_number_of_descriptors; i++) {
947 new_result->CopyFrom(i, *result, i, witness); 946 new_result->CopyFrom(i, *result, i, witness);
948 } 947 }
949 new_result->SetLastAdded(result->LastAdded());
950 map->set_instance_descriptors(*new_result); 948 map->set_instance_descriptors(*new_result);
951 } 949 }
952 } 950 }
953 951
954 952
955 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, 953 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
956 PretenureFlag pretenure) { 954 PretenureFlag pretenure) {
957 CALL_HEAP_FUNCTION( 955 CALL_HEAP_FUNCTION(
958 isolate(), 956 isolate(),
959 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); 957 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject);
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 1459
1462 1460
1463 Handle<Object> Factory::ToBoolean(bool value) { 1461 Handle<Object> Factory::ToBoolean(bool value) {
1464 return Handle<Object>(value 1462 return Handle<Object>(value
1465 ? isolate()->heap()->true_value() 1463 ? isolate()->heap()->true_value()
1466 : isolate()->heap()->false_value()); 1464 : isolate()->heap()->false_value());
1467 } 1465 }
1468 1466
1469 1467
1470 } } // namespace v8::internal 1468 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/macro-assembler-arm.cc ('k') | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698