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

Side by Side Diff: src/transitions.cc

Issue 10697015: Separating transitions from descriptors. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
OLDNEW
(Empty)
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "v8.h"
29
30 #include "objects.h"
31 #include "transitions-inl.h"
32 #include "transitions.h"
Jakob Kummerow 2012/06/29 16:31:36 transitions-inl.h is enough.
Toon Verwaest 2012/07/05 12:56:11 Done.
33 #include "utils.h"
34
35 namespace v8 {
36 namespace internal {
37
38
39 MaybeObject* TransitionArray::Allocate(int number_of_transitions) {
40 Heap* heap = Isolate::Current()->heap();
41 // Use FixedArray to not use DescriptorArray::cast on incomplete object.
42 FixedArray* array;
43 { MaybeObject* maybe_array =
44 heap->AllocateFixedArray(ToKeyIndex(number_of_transitions));
45 if (!maybe_array->To(&array)) return maybe_array;
46 }
47
48 array->set(kElementsTransitionIndex, Smi::FromInt(0));
49 return array;
50 }
51
52
53 void TransitionArray::CopyFrom(TransitionArray* origin,
54 int origin_transition,
55 int target_transition) {
56 this->Set(target_transition,
57 origin->GetKey(origin_transition),
58 origin->GetValue(origin_transition));
59 }
60
61
62 static bool InsertionPointFound(String* key1, String* key2) {
63 return key1->Hash() > key2->Hash();
64 }
65
66
67 bool TransitionArray::TransitionsTo(Object* target) {
68 if (this->elements() == reinterpret_cast<Map*>(target)) return true;
69 for (int i = 0; i < this->number_of_transitions(); ++i) {
70 Object* value = GetValue(i);
71 if (value->IsAccessorPair()) {
72 AccessorPair* accessors = AccessorPair::cast(value);
73 if (accessors->getter() == target ||
74 accessors->setter() == target) return true;
75 } else {
76 if (target == value) return true;
77 }
78 }
79 return false;
80 }
81
82
83 MaybeObject* TransitionArray::CopyInsert(String* name, Object* value) {
84 TransitionArray* result;
85 if (this == NULL) {
Jakob Kummerow 2012/06/29 16:31:36 can this happen?
Toon Verwaest 2012/07/05 12:56:11 Done.
86 { MaybeObject* maybe_array;
87 maybe_array = TransitionArray::Allocate(1);
88 if (!maybe_array->To(&result)) return maybe_array;
89 }
90
91 result->Set(0, name, value);
92 return result;
93 }
94
95 int number_of_transitions = this->number_of_transitions();
96 int new_size = number_of_transitions;
97
98 int insertion_index = this->Search(name);
99 if (insertion_index == kNotFound) ++new_size;
100
101 { MaybeObject* maybe_array;
102 maybe_array = TransitionArray::Allocate(new_size);
103 if (!maybe_array->To(&result)) return maybe_array;
104 }
105
106 if (HasElementsTransition()) result->set_elements(elements());
107
108 if (insertion_index != kNotFound) {
109 for (int i = 0; i < number_of_transitions; ++i) {
110 if (i != insertion_index) result->CopyFrom(this, i, i);
111 }
112 result->Set(insertion_index, name, value);
113 return result;
114 }
115
116 insertion_index = 0;
117 for (; insertion_index < number_of_transitions; ++insertion_index) {
118 if (InsertionPointFound(GetKey(insertion_index), name)) break;
119 result->CopyFrom(this, insertion_index, insertion_index);
120 }
121
122 result->Set(insertion_index, name, value);
123
124 for (; insertion_index < number_of_transitions; ++insertion_index) {
125 result->CopyFrom(this, insertion_index, insertion_index + 1);
126 }
127
128 return result;
129 }
130
131
132 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698