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/factory.cc

Issue 10830005: In-place trimming of descriptor array when appending callbacks. (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/factory.h ('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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 Code); 885 Code);
886 } 886 }
887 887
888 888
889 Handle<String> Factory::SymbolFromString(Handle<String> value) { 889 Handle<String> Factory::SymbolFromString(Handle<String> value) {
890 CALL_HEAP_FUNCTION(isolate(), 890 CALL_HEAP_FUNCTION(isolate(),
891 isolate()->heap()->LookupSymbol(*value), String); 891 isolate()->heap()->LookupSymbol(*value), String);
892 } 892 }
893 893
894 894
895 void Factory::CopyAppendCallbackDescriptors(Handle<Map> map,
896 Handle<Object> descriptors) {
897 Handle<DescriptorArray> array(map->instance_descriptors());
898 v8::NeanderArray callbacks(descriptors);
899 int nof_callbacks = callbacks.length();
900 int descriptor_count = array->number_of_descriptors();
901 Handle<DescriptorArray> result =
902 NewDescriptorArray(descriptor_count + nof_callbacks);
903
904 // Ensure that marking will not progress and change color of objects.
905 DescriptorArray::WhitenessWitness witness(*result);
906
907 // Copy the descriptors from the array.
908 if (0 < descriptor_count) {
909 for (int i = 0; i < descriptor_count; i++) {
910 result->CopyFrom(i, *array, i, witness);
911 }
912 }
913
914 map->set_instance_descriptors(*result);
915
916 // Fill in new callback descriptors. Process the callbacks from
917 // back to front so that the last callback with a given name takes
918 // precedence over previously added callbacks with that name.
919 for (int i = nof_callbacks - 1; i >= 0; i--) {
920 Handle<AccessorInfo> entry =
921 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i)));
922 // Ensure the key is a symbol before writing into the instance descriptor.
923 Handle<String> key =
924 SymbolFromString(Handle<String>(String::cast(entry->name())));
925 // Check if a descriptor with this name already exists before writing.
926 if (LinearSearch(*result, *key, map->NumberOfSetDescriptors()) ==
927 DescriptorArray::kNotFound) {
928 CallbacksDescriptor desc(*key, *entry, entry->property_attributes());
929 map->AppendDescriptor(&desc, witness);
930 }
931 }
932
933 int new_number_of_descriptors = map->NumberOfSetDescriptors();
934 // Reinstall the original descriptor array if no new elements were added.
935 if (new_number_of_descriptors == descriptor_count) {
936 map->set_instance_descriptors(*array);
937 return;
938 }
939
940 // If duplicates were detected, allocate a result of the right size
941 // and transfer the elements.
942 if (new_number_of_descriptors < result->length()) {
943 Handle<DescriptorArray> new_result =
944 NewDescriptorArray(new_number_of_descriptors);
945 for (int i = 0; i < new_number_of_descriptors; i++) {
946 new_result->CopyFrom(i, *result, i, witness);
947 }
948 map->set_instance_descriptors(*new_result);
949 }
950 }
951
952
953 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, 895 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
954 PretenureFlag pretenure) { 896 PretenureFlag pretenure) {
955 CALL_HEAP_FUNCTION( 897 CALL_HEAP_FUNCTION(
956 isolate(), 898 isolate(),
957 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); 899 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject);
958 } 900 }
959 901
960 902
961 Handle<JSModule> Factory::NewJSModule(Handle<Context> context, 903 Handle<JSModule> Factory::NewJSModule(Handle<Context> context,
962 Handle<ScopeInfo> scope_info) { 904 Handle<ScopeInfo> scope_info) {
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 } 1272 }
1331 1273
1332 result->shared()->set_function_data(*obj); 1274 result->shared()->set_function_data(*obj);
1333 result->shared()->set_construct_stub(*construct_stub); 1275 result->shared()->set_construct_stub(*construct_stub);
1334 result->shared()->DontAdaptArguments(); 1276 result->shared()->DontAdaptArguments();
1335 1277
1336 // Recursively copy parent templates' accessors, 'data' may be modified. 1278 // Recursively copy parent templates' accessors, 'data' may be modified.
1337 while (true) { 1279 while (true) {
1338 Handle<Object> props = Handle<Object>(obj->property_accessors()); 1280 Handle<Object> props = Handle<Object>(obj->property_accessors());
1339 if (!props->IsUndefined()) { 1281 if (!props->IsUndefined()) {
1340 CopyAppendCallbackDescriptors(map, props); 1282 Map::CopyAppendCallbackDescriptors(map, props);
1341 } 1283 }
1342 Handle<Object> parent = Handle<Object>(obj->parent_template()); 1284 Handle<Object> parent = Handle<Object>(obj->parent_template());
1343 if (parent->IsUndefined()) break; 1285 if (parent->IsUndefined()) break;
1344 obj = Handle<FunctionTemplateInfo>::cast(parent); 1286 obj = Handle<FunctionTemplateInfo>::cast(parent);
1345 } 1287 }
1346 1288
1347 ASSERT(result->shared()->IsApiFunction()); 1289 ASSERT(result->shared()->IsApiFunction());
1348 return result; 1290 return result;
1349 } 1291 }
1350 1292
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 1401
1460 1402
1461 Handle<Object> Factory::ToBoolean(bool value) { 1403 Handle<Object> Factory::ToBoolean(bool value) {
1462 return Handle<Object>(value 1404 return Handle<Object>(value
1463 ? isolate()->heap()->true_value() 1405 ? isolate()->heap()->true_value()
1464 : isolate()->heap()->false_value()); 1406 : isolate()->heap()->false_value());
1465 } 1407 }
1466 1408
1467 1409
1468 } } // namespace v8::internal 1410 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698