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

Side by Side Diff: src/objects.cc

Issue 10066046: Tiny DescriptorArray cleanup. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed copyright year Created 8 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 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 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2315 // Get the cached index for the descriptors lookup, or find and cache it. 2315 // Get the cached index for the descriptors lookup, or find and cache it.
2316 DescriptorArray* descriptors = instance_descriptors(); 2316 DescriptorArray* descriptors = instance_descriptors();
2317 DescriptorLookupCache* cache = GetIsolate()->descriptor_lookup_cache(); 2317 DescriptorLookupCache* cache = GetIsolate()->descriptor_lookup_cache();
2318 int index = cache->Lookup(descriptors, sentinel_name); 2318 int index = cache->Lookup(descriptors, sentinel_name);
2319 if (index == DescriptorLookupCache::kAbsent) { 2319 if (index == DescriptorLookupCache::kAbsent) {
2320 index = descriptors->Search(sentinel_name); 2320 index = descriptors->Search(sentinel_name);
2321 cache->Update(descriptors, sentinel_name, index); 2321 cache->Update(descriptors, sentinel_name, index);
2322 } 2322 }
2323 // If the transition already exists, return its descriptor. 2323 // If the transition already exists, return its descriptor.
2324 if (index != DescriptorArray::kNotFound) { 2324 if (index != DescriptorArray::kNotFound) {
2325 PropertyDetails details(descriptors->GetDetails(index)); 2325 PropertyDetails details = descriptors->GetDetails(index);
2326 if (details.type() == ELEMENTS_TRANSITION) { 2326 if (details.type() == ELEMENTS_TRANSITION) {
2327 return descriptors->GetValue(index); 2327 return descriptors->GetValue(index);
2328 } else { 2328 } else {
2329 if (safe_to_add_transition != NULL) { 2329 if (safe_to_add_transition != NULL) {
2330 *safe_to_add_transition = false; 2330 *safe_to_add_transition = false;
2331 } 2331 }
2332 } 2332 }
2333 } 2333 }
2334 return NULL; 2334 return NULL;
2335 } 2335 }
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
3337 } else { 3337 } else {
3338 property_count += 2; // Make space for two more properties. 3338 property_count += 2; // Make space for two more properties.
3339 } 3339 }
3340 StringDictionary* dictionary; 3340 StringDictionary* dictionary;
3341 { MaybeObject* maybe_dictionary = StringDictionary::Allocate(property_count); 3341 { MaybeObject* maybe_dictionary = StringDictionary::Allocate(property_count);
3342 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; 3342 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
3343 } 3343 }
3344 3344
3345 DescriptorArray* descs = map_of_this->instance_descriptors(); 3345 DescriptorArray* descs = map_of_this->instance_descriptors();
3346 for (int i = 0; i < descs->number_of_descriptors(); i++) { 3346 for (int i = 0; i < descs->number_of_descriptors(); i++) {
3347 PropertyDetails details(descs->GetDetails(i)); 3347 PropertyDetails details = descs->GetDetails(i);
3348 switch (details.type()) { 3348 switch (details.type()) {
3349 case CONSTANT_FUNCTION: { 3349 case CONSTANT_FUNCTION: {
3350 PropertyDetails d = 3350 PropertyDetails d =
3351 PropertyDetails(details.attributes(), NORMAL, details.index()); 3351 PropertyDetails(details.attributes(), NORMAL, details.index());
3352 Object* value = descs->GetConstantFunction(i); 3352 Object* value = descs->GetConstantFunction(i);
3353 MaybeObject* maybe_dictionary = 3353 MaybeObject* maybe_dictionary =
3354 dictionary->Add(descs->GetKey(i), value, d); 3354 dictionary->Add(descs->GetKey(i), value, d);
3355 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; 3355 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;
3356 break; 3356 break;
3357 } 3357 }
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
4199 } 4199 }
4200 } 4200 }
4201 return true; 4201 return true;
4202 } 4202 }
4203 4203
4204 4204
4205 int Map::NumberOfDescribedProperties(PropertyAttributes filter) { 4205 int Map::NumberOfDescribedProperties(PropertyAttributes filter) {
4206 int result = 0; 4206 int result = 0;
4207 DescriptorArray* descs = instance_descriptors(); 4207 DescriptorArray* descs = instance_descriptors();
4208 for (int i = 0; i < descs->number_of_descriptors(); i++) { 4208 for (int i = 0; i < descs->number_of_descriptors(); i++) {
4209 PropertyDetails details(descs->GetDetails(i)); 4209 PropertyDetails details = descs->GetDetails(i);
4210 if (descs->IsProperty(i) && (details.attributes() & filter) == 0) { 4210 if (descs->IsProperty(i) && (details.attributes() & filter) == 0) {
4211 result++; 4211 result++;
4212 } 4212 }
4213 } 4213 }
4214 return result; 4214 return result;
4215 } 4215 }
4216 4216
4217 4217
4218 int Map::PropertyIndexFor(String* name) { 4218 int Map::PropertyIndexFor(String* name) {
4219 DescriptorArray* descs = instance_descriptors(); 4219 DescriptorArray* descs = instance_descriptors();
(...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after
5680 CALL_HEAP_FUNCTION_VOID(dst->GetIsolate(), 5680 CALL_HEAP_FUNCTION_VOID(dst->GetIsolate(),
5681 dst->CopyFrom(dst_index, *src, src_index, witness)); 5681 dst->CopyFrom(dst_index, *src, src_index, witness));
5682 } 5682 }
5683 5683
5684 5684
5685 MaybeObject* DescriptorArray::CopyFrom(int dst_index, 5685 MaybeObject* DescriptorArray::CopyFrom(int dst_index,
5686 DescriptorArray* src, 5686 DescriptorArray* src,
5687 int src_index, 5687 int src_index,
5688 const WhitenessWitness& witness) { 5688 const WhitenessWitness& witness) {
5689 Object* value = src->GetValue(src_index); 5689 Object* value = src->GetValue(src_index);
5690 PropertyDetails details(src->GetDetails(src_index)); 5690 PropertyDetails details = src->GetDetails(src_index);
5691 if (details.type() == CALLBACKS && value->IsAccessorPair()) { 5691 if (details.type() == CALLBACKS && value->IsAccessorPair()) {
5692 MaybeObject* maybe_copy = 5692 MaybeObject* maybe_copy =
5693 AccessorPair::cast(value)->CopyWithoutTransitions(); 5693 AccessorPair::cast(value)->CopyWithoutTransitions();
5694 if (!maybe_copy->To(&value)) return maybe_copy; 5694 if (!maybe_copy->To(&value)) return maybe_copy;
5695 } 5695 }
5696 Descriptor desc(src->GetKey(src_index), value, details); 5696 Descriptor desc(src->GetKey(src_index), value, details);
5697 Set(dst_index, &desc, witness); 5697 Set(dst_index, &desc, witness);
5698 return this; 5698 return this;
5699 } 5699 }
5700 5700
(...skipping 22 matching lines...) Expand all
5723 } 5723 }
5724 5724
5725 // If key is in descriptor, we replace it in-place when filtering. 5725 // If key is in descriptor, we replace it in-place when filtering.
5726 // Count a null descriptor for key as inserted, not replaced. 5726 // Count a null descriptor for key as inserted, not replaced.
5727 int index = Search(descriptor->GetKey()); 5727 int index = Search(descriptor->GetKey());
5728 const bool replacing = (index != kNotFound); 5728 const bool replacing = (index != kNotFound);
5729 bool keep_enumeration_index = false; 5729 bool keep_enumeration_index = false;
5730 if (replacing) { 5730 if (replacing) {
5731 // We are replacing an existing descriptor. We keep the enumeration 5731 // We are replacing an existing descriptor. We keep the enumeration
5732 // index of a visible property. 5732 // index of a visible property.
5733 PropertyType t = PropertyDetails(GetDetails(index)).type(); 5733 PropertyType t = GetDetails(index).type();
5734 if (t == CONSTANT_FUNCTION || 5734 if (t == CONSTANT_FUNCTION ||
5735 t == FIELD || 5735 t == FIELD ||
5736 t == CALLBACKS || 5736 t == CALLBACKS ||
5737 t == INTERCEPTOR) { 5737 t == INTERCEPTOR) {
5738 keep_enumeration_index = true; 5738 keep_enumeration_index = true;
5739 } else if (remove_transitions) { 5739 } else if (remove_transitions) {
5740 // Replaced descriptor has been counted as removed if it is 5740 // Replaced descriptor has been counted as removed if it is
5741 // a transition that will be replaced. Adjust count in this case. 5741 // a transition that will be replaced. Adjust count in this case.
5742 ++new_size; 5742 ++new_size;
5743 } 5743 }
5744 } else { 5744 } else {
5745 ++new_size; 5745 ++new_size;
5746 } 5746 }
5747 5747
5748 DescriptorArray* new_descriptors; 5748 DescriptorArray* new_descriptors;
5749 { MaybeObject* maybe_result = Allocate(new_size); 5749 { MaybeObject* maybe_result = Allocate(new_size);
5750 if (!maybe_result->To(&new_descriptors)) return maybe_result; 5750 if (!maybe_result->To(&new_descriptors)) return maybe_result;
5751 } 5751 }
5752 5752
5753 DescriptorArray::WhitenessWitness witness(new_descriptors); 5753 DescriptorArray::WhitenessWitness witness(new_descriptors);
5754 5754
5755 // Set the enumeration index in the descriptors and set the enumeration index 5755 // Set the enumeration index in the descriptors and set the enumeration index
5756 // in the result. 5756 // in the result.
5757 int enumeration_index = NextEnumerationIndex(); 5757 int enumeration_index = NextEnumerationIndex();
5758 if (!descriptor->ContainsTransition()) { 5758 if (!descriptor->ContainsTransition()) {
5759 if (keep_enumeration_index) { 5759 if (keep_enumeration_index) {
5760 descriptor->SetEnumerationIndex( 5760 descriptor->SetEnumerationIndex(GetDetails(index).index());
5761 PropertyDetails(GetDetails(index)).index());
5762 } else { 5761 } else {
5763 descriptor->SetEnumerationIndex(enumeration_index); 5762 descriptor->SetEnumerationIndex(enumeration_index);
5764 ++enumeration_index; 5763 ++enumeration_index;
5765 } 5764 }
5766 } 5765 }
5767 new_descriptors->SetNextEnumerationIndex(enumeration_index); 5766 new_descriptors->SetNextEnumerationIndex(enumeration_index);
5768 5767
5769 // Copy the descriptors, filtering out transitions and null descriptors, 5768 // Copy the descriptors, filtering out transitions and null descriptors,
5770 // and inserting or replacing a descriptor. 5769 // and inserting or replacing a descriptor.
5771 int to_index = 0; 5770 int to_index = 0;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
5895 continue; 5894 continue;
5896 } 5895 }
5897 if (mid_hash < hash) { 5896 if (mid_hash < hash) {
5898 low = mid + 1; 5897 low = mid + 1;
5899 continue; 5898 continue;
5900 } 5899 }
5901 // Found an element with the same hash-code. 5900 // Found an element with the same hash-code.
5902 ASSERT(hash == mid_hash); 5901 ASSERT(hash == mid_hash);
5903 // There might be more, so we find the first one and 5902 // There might be more, so we find the first one and
5904 // check them all to see if we have a match. 5903 // check them all to see if we have a match.
5905 if (name == mid_name && !is_null_descriptor(mid)) return mid; 5904 if (name == mid_name && !IsNullDescriptor(mid)) return mid;
5906 while ((mid > low) && (GetKey(mid - 1)->Hash() == hash)) mid--; 5905 while ((mid > low) && (GetKey(mid - 1)->Hash() == hash)) mid--;
5907 for (; (mid <= high) && (GetKey(mid)->Hash() == hash); mid++) { 5906 for (; (mid <= high) && (GetKey(mid)->Hash() == hash); mid++) {
5908 if (GetKey(mid)->Equals(name) && !is_null_descriptor(mid)) return mid; 5907 if (GetKey(mid)->Equals(name) && !IsNullDescriptor(mid)) return mid;
5909 } 5908 }
5910 break; 5909 break;
5911 } 5910 }
5912 return kNotFound; 5911 return kNotFound;
5913 } 5912 }
5914 5913
5915 5914
5916 int DescriptorArray::LinearSearch(String* name, int len) { 5915 int DescriptorArray::LinearSearch(String* name, int len) {
5917 uint32_t hash = name->Hash(); 5916 uint32_t hash = name->Hash();
5918 for (int number = 0; number < len; number++) { 5917 for (int number = 0; number < len; number++) {
5919 String* entry = GetKey(number); 5918 String* entry = GetKey(number);
5920 if ((entry->Hash() == hash) && 5919 if ((entry->Hash() == hash) &&
5921 name->Equals(entry) && 5920 name->Equals(entry) &&
5922 !is_null_descriptor(number)) { 5921 !IsNullDescriptor(number)) {
5923 return number; 5922 return number;
5924 } 5923 }
5925 } 5924 }
5926 return kNotFound; 5925 return kNotFound;
5927 } 5926 }
5928 5927
5929 5928
5930 MaybeObject* AccessorPair::CopyWithoutTransitions() { 5929 MaybeObject* AccessorPair::CopyWithoutTransitions() {
5931 Heap* heap = GetHeap(); 5930 Heap* heap = GetHeap();
5932 AccessorPair* copy; 5931 AccessorPair* copy;
(...skipping 7031 matching lines...) Expand 10 before | Expand all | Expand 10 after
12964 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 12963 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
12965 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 12964 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
12966 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 12965 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
12967 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 12966 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
12968 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 12967 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
12969 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 12968 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
12970 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 12969 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
12971 } 12970 }
12972 12971
12973 } } // namespace v8::internal 12972 } } // 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