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

Side by Side Diff: src/factory.cc

Issue 10575032: In-place shrinking of descriptor arrays with non-live transitions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing comments Created 8 years, 6 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/ic.cc » ('j') | src/ic.cc » ('J')
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 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 CALL_HEAP_FUNCTION(isolate(), 932 CALL_HEAP_FUNCTION(isolate(),
933 isolate()->heap()->LookupSymbol(*value), String); 933 isolate()->heap()->LookupSymbol(*value), String);
934 } 934 }
935 935
936 936
937 Handle<DescriptorArray> Factory::CopyAppendCallbackDescriptors( 937 Handle<DescriptorArray> Factory::CopyAppendCallbackDescriptors(
938 Handle<DescriptorArray> array, 938 Handle<DescriptorArray> array,
939 Handle<Object> descriptors) { 939 Handle<Object> descriptors) {
940 v8::NeanderArray callbacks(descriptors); 940 v8::NeanderArray callbacks(descriptors);
941 int nof_callbacks = callbacks.length(); 941 int nof_callbacks = callbacks.length();
942 int descriptor_count = array->number_of_descriptors();
942 Handle<DescriptorArray> result = 943 Handle<DescriptorArray> result =
943 NewDescriptorArray(array->number_of_descriptors() + nof_callbacks); 944 NewDescriptorArray(descriptor_count + nof_callbacks);
944
945 // Number of descriptors added to the result so far.
946 int descriptor_count = 0;
947 945
948 // Ensure that marking will not progress and change color of objects. 946 // Ensure that marking will not progress and change color of objects.
949 DescriptorArray::WhitenessWitness witness(*result); 947 DescriptorArray::WhitenessWitness witness(*result);
950 948
951 // Copy the descriptors from the array. 949 // Copy the descriptors from the array.
952 for (int i = 0; i < array->number_of_descriptors(); i++) { 950 for (int i = 0; i < descriptor_count; i++) {
953 if (!array->IsNullDescriptor(i)) { 951 DescriptorArray::CopyFrom(result, i, array, i, witness);
954 DescriptorArray::CopyFrom(result, descriptor_count++, array, i, witness);
955 }
956 } 952 }
957 953
958 // Number of duplicates detected.
959 int duplicates = 0;
960
961 // Fill in new callback descriptors. Process the callbacks from 954 // Fill in new callback descriptors. Process the callbacks from
962 // back to front so that the last callback with a given name takes 955 // back to front so that the last callback with a given name takes
963 // precedence over previously added callbacks with that name. 956 // precedence over previously added callbacks with that name.
964 for (int i = nof_callbacks - 1; i >= 0; i--) { 957 for (int i = nof_callbacks - 1; i >= 0; i--) {
965 Handle<AccessorInfo> entry = 958 Handle<AccessorInfo> entry =
966 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); 959 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i)));
967 // Ensure the key is a symbol before writing into the instance descriptor. 960 // Ensure the key is a symbol before writing into the instance descriptor.
968 Handle<String> key = 961 Handle<String> key =
969 SymbolFromString(Handle<String>(String::cast(entry->name()))); 962 SymbolFromString(Handle<String>(String::cast(entry->name())));
970 // Check if a descriptor with this name already exists before writing. 963 // Check if a descriptor with this name already exists before writing.
971 if (result->LinearSearch(EXPECT_UNSORTED, *key, descriptor_count) == 964 if (result->LinearSearch(EXPECT_UNSORTED, *key, descriptor_count) ==
972 DescriptorArray::kNotFound) { 965 DescriptorArray::kNotFound) {
973 CallbacksDescriptor desc(*key, *entry, entry->property_attributes()); 966 CallbacksDescriptor desc(*key, *entry, entry->property_attributes());
974 result->Set(descriptor_count, &desc, witness); 967 result->Set(descriptor_count, &desc, witness);
975 descriptor_count++; 968 descriptor_count++;
976 } else {
977 duplicates++;
978 } 969 }
979 } 970 }
980 971
981 // If duplicates were detected, allocate a result of the right size 972 // If duplicates were detected, allocate a result of the right size
982 // and transfer the elements. 973 // and transfer the elements.
983 if (duplicates > 0) { 974 if (descriptor_count < result->length()) {
984 int number_of_descriptors = result->number_of_descriptors() - duplicates; 975 Handle<DescriptorArray> new_result = NewDescriptorArray(descriptor_count);
985 Handle<DescriptorArray> new_result = 976 for (int i = 0; i < descriptor_count; i++) {
986 NewDescriptorArray(number_of_descriptors);
987 for (int i = 0; i < number_of_descriptors; i++) {
988 DescriptorArray::CopyFrom(new_result, i, result, i, witness); 977 DescriptorArray::CopyFrom(new_result, i, result, i, witness);
989 } 978 }
990 result = new_result; 979 result = new_result;
991 } 980 }
992 981
993 // Sort the result before returning. 982 // Sort the result before returning.
994 result->Sort(witness); 983 result->Sort(witness);
995 return result; 984 return result;
996 } 985 }
997 986
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 1498
1510 1499
1511 Handle<Object> Factory::ToBoolean(bool value) { 1500 Handle<Object> Factory::ToBoolean(bool value) {
1512 return Handle<Object>(value 1501 return Handle<Object>(value
1513 ? isolate()->heap()->true_value() 1502 ? isolate()->heap()->true_value()
1514 : isolate()->heap()->false_value()); 1503 : isolate()->heap()->false_value());
1515 } 1504 }
1516 1505
1517 1506
1518 } } // namespace v8::internal 1507 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/ic.cc » ('j') | src/ic.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698