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

Side by Side Diff: src/objects.h

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/factory.cc ('k') | src/objects.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 2457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 inline void ClearTransitions(); 2468 inline void ClearTransitions();
2469 2469
2470 // Returns the number of descriptors in the array. 2470 // Returns the number of descriptors in the array.
2471 int number_of_descriptors() { 2471 int number_of_descriptors() {
2472 ASSERT(MayContainTransitions() || IsEmpty()); 2472 ASSERT(MayContainTransitions() || IsEmpty());
2473 int len = length(); 2473 int len = length();
2474 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize; 2474 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize;
2475 } 2475 }
2476 2476
2477 inline int number_of_entries() { return number_of_descriptors(); } 2477 inline int number_of_entries() { return number_of_descriptors(); }
2478 inline int NextEnumerationIndex() { return number_of_descriptors() + 1; }
2478 2479
2479 int LastAdded() { 2480 int LastAdded() {
2480 ASSERT(!IsEmpty()); 2481 ASSERT(!IsEmpty());
2481 Object* obj = get(kLastAddedIndex); 2482 Object* obj = get(kLastAddedIndex);
2482 if (obj->IsSmi()) { 2483 if (obj->IsSmi()) {
2483 return Smi::cast(obj)->value(); 2484 return Smi::cast(obj)->value();
2484 } else { 2485 } else {
2485 Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeLastAdded); 2486 Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeLastAdded);
2486 return Smi::cast(index)->value(); 2487 return Smi::cast(index)->value();
2487 } 2488 }
2488 } 2489 }
2489 2490
2490 int NextEnumerationIndex() {
2491 if (number_of_descriptors() == 0) {
2492 return PropertyDetails::kInitialIndex;
2493 }
2494 return GetDetails(LastAdded()).index() + 1;
2495 }
2496
2497 // Set index of the last added descriptor and flush any enum cache. 2491 // Set index of the last added descriptor and flush any enum cache.
2498 void SetLastAdded(int index) { 2492 void SetLastAdded(int index) {
2499 ASSERT(!IsEmpty() || index > 0); 2493 ASSERT(!IsEmpty() || index > 0);
2500 set(kLastAddedIndex, Smi::FromInt(index)); 2494 set(kLastAddedIndex, Smi::FromInt(index));
2501 } 2495 }
2502 2496
2497 int NumberOfSetDescriptors() {
2498 ASSERT(!IsEmpty());
2499 if (LastAdded() == kNoneAdded) return 0;
2500 return GetDetails(LastAdded()).index();
2501 }
2502
2503 bool HasEnumCache() { 2503 bool HasEnumCache() {
2504 return !IsEmpty() && !get(kLastAddedIndex)->IsSmi(); 2504 return !IsEmpty() && !get(kLastAddedIndex)->IsSmi();
2505 } 2505 }
2506 2506
2507 Object* GetEnumCache() { 2507 Object* GetEnumCache() {
2508 ASSERT(HasEnumCache()); 2508 ASSERT(HasEnumCache());
2509 FixedArray* bridge = FixedArray::cast(get(kLastAddedIndex)); 2509 FixedArray* bridge = FixedArray::cast(get(kLastAddedIndex));
2510 return bridge->get(kEnumCacheBridgeCacheIndex); 2510 return bridge->get(kEnumCacheBridgeCacheIndex);
2511 } 2511 }
2512 2512
(...skipping 26 matching lines...) Expand all
2539 inline int GetFieldIndex(int descriptor_number); 2539 inline int GetFieldIndex(int descriptor_number);
2540 inline JSFunction* GetConstantFunction(int descriptor_number); 2540 inline JSFunction* GetConstantFunction(int descriptor_number);
2541 inline Object* GetCallbacksObject(int descriptor_number); 2541 inline Object* GetCallbacksObject(int descriptor_number);
2542 inline AccessorDescriptor* GetCallbacks(int descriptor_number); 2542 inline AccessorDescriptor* GetCallbacks(int descriptor_number);
2543 2543
2544 // Accessor for complete descriptor. 2544 // Accessor for complete descriptor.
2545 inline void Get(int descriptor_number, Descriptor* desc); 2545 inline void Get(int descriptor_number, Descriptor* desc);
2546 inline void Set(int descriptor_number, 2546 inline void Set(int descriptor_number,
2547 Descriptor* desc, 2547 Descriptor* desc,
2548 const WhitenessWitness&); 2548 const WhitenessWitness&);
2549 // Append automatically sets the enumeration index. This should only be used
2550 // to add descriptors in bulk at the end, followed by sorting the descriptor
2551 // array.
2552 inline void Append(Descriptor* desc,
2553 const WhitenessWitness&);
2549 2554
2550 // Transfer a complete descriptor from the src descriptor array to the dst 2555 // Transfer a complete descriptor from the src descriptor array to the dst
2551 // one, dropping map transitions in CALLBACKS. 2556 // one, dropping map transitions in CALLBACKS.
2552 static void CopyFrom(Handle<DescriptorArray> dst, 2557 static void CopyFrom(Handle<DescriptorArray> dst,
2553 int dst_index, 2558 int dst_index,
2554 Handle<DescriptorArray> src, 2559 Handle<DescriptorArray> src,
2555 int src_index, 2560 int src_index,
2556 const WhitenessWitness& witness); 2561 const WhitenessWitness& witness);
2557 2562
2558 // Transfer a complete descriptor from the src descriptor array to this 2563 // Transfer a complete descriptor from the src descriptor array to this
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2606 // empty descriptor array object if number_of_descriptors is 0. 2611 // empty descriptor array object if number_of_descriptors is 0.
2607 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors, 2612 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors,
2608 SharedMode shared_mode); 2613 SharedMode shared_mode);
2609 2614
2610 // Casting. 2615 // Casting.
2611 static inline DescriptorArray* cast(Object* obj); 2616 static inline DescriptorArray* cast(Object* obj);
2612 2617
2613 // Constant for denoting key was not found. 2618 // Constant for denoting key was not found.
2614 static const int kNotFound = -1; 2619 static const int kNotFound = -1;
2615 2620
2621 // Constant for denoting that the LastAdded field was not yet set.
2622 static const int kNoneAdded = -1;
2623
2616 static const int kBackPointerStorageIndex = 0; 2624 static const int kBackPointerStorageIndex = 0;
2617 static const int kLastAddedIndex = 1; 2625 static const int kLastAddedIndex = 1;
2618 static const int kTransitionsIndex = 2; 2626 static const int kTransitionsIndex = 2;
2619 static const int kFirstIndex = 3; 2627 static const int kFirstIndex = 3;
2620 2628
2621 // The length of the "bridge" to the enum cache. 2629 // The length of the "bridge" to the enum cache.
2622 static const int kEnumCacheBridgeLength = 3; 2630 static const int kEnumCacheBridgeLength = 3;
2623 static const int kEnumCacheBridgeLastAdded = 0; 2631 static const int kEnumCacheBridgeLastAdded = 0;
2624 static const int kEnumCacheBridgeCacheIndex = 1; 2632 static const int kEnumCacheBridgeCacheIndex = 1;
2625 static const int kEnumCacheBridgeIndicesCacheIndex = 2; 2633 static const int kEnumCacheBridgeIndicesCacheIndex = 2;
(...skipping 6259 matching lines...) Expand 10 before | Expand all | Expand 10 after
8885 } else { 8893 } else {
8886 value &= ~(1 << bit_position); 8894 value &= ~(1 << bit_position);
8887 } 8895 }
8888 return value; 8896 return value;
8889 } 8897 }
8890 }; 8898 };
8891 8899
8892 } } // namespace v8::internal 8900 } } // namespace v8::internal
8893 8901
8894 #endif // V8_OBJECTS_H_ 8902 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698