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

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: Using WhitenessWitness in TransitionArray code. 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/transitions.h ('k') | src/transitions-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
(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 "utils.h"
33
34 namespace v8 {
35 namespace internal {
36
37
38 MaybeObject* TransitionArray::Allocate(int number_of_transitions) {
39 Heap* heap = Isolate::Current()->heap();
40 // Use FixedArray to not use DescriptorArray::cast on incomplete object.
41 FixedArray* array;
42 { MaybeObject* maybe_array =
43 heap->AllocateFixedArray(ToKeyIndex(number_of_transitions));
44 if (!maybe_array->To(&array)) return maybe_array;
45 }
46
47 array->set(kElementsTransitionIndex, Smi::FromInt(0));
48 return array;
49 }
50
51
52 void TransitionArray::CopyFrom(TransitionArray* origin,
53 int origin_transition,
54 int target_transition,
55 const WhitenessWitness& witness) {
56 this->Set(target_transition,
57 origin->GetKey(origin_transition),
58 origin->GetValue(origin_transition),
59 witness);
60 }
61
62
63 static bool InsertionPointFound(String* key1, String* key2) {
64 return key1->Hash() > key2->Hash();
65 }
66
67
68 MaybeObject* TransitionArray::NewWith(String* name, Object* value) {
69 TransitionArray* result;
70
71 { MaybeObject* maybe_array;
72 maybe_array = TransitionArray::Allocate(1);
73 if (!maybe_array->To(&result)) return maybe_array;
74 }
75
76 FixedArray::WhitenessWitness witness(result);
77
78 result->Set(0, name, value, witness);
79 return result;
80 }
81
82
83 MaybeObject* TransitionArray::CopyInsert(String* name, Object* value) {
84 TransitionArray* result;
85
86 int number_of_transitions = this->number_of_transitions();
87 int new_size = number_of_transitions;
88
89 int insertion_index = this->Search(name);
90 if (insertion_index == kNotFound) ++new_size;
91
92 { MaybeObject* maybe_array;
93 maybe_array = TransitionArray::Allocate(new_size);
94 if (!maybe_array->To(&result)) return maybe_array;
95 }
96
97 if (HasElementsTransition()) {
98 result->set_elements_transition(elements_transition());
99 }
100
101 FixedArray::WhitenessWitness witness(result);
102
103 if (insertion_index != kNotFound) {
104 for (int i = 0; i < number_of_transitions; ++i) {
105 if (i != insertion_index) result->CopyFrom(this, i, i, witness);
106 }
107 result->Set(insertion_index, name, value, witness);
108 return result;
109 }
110
111 insertion_index = 0;
112 for (; insertion_index < number_of_transitions; ++insertion_index) {
113 if (InsertionPointFound(GetKey(insertion_index), name)) break;
114 result->CopyFrom(this, insertion_index, insertion_index, witness);
115 }
116
117 result->Set(insertion_index, name, value, witness);
118
119 for (; insertion_index < number_of_transitions; ++insertion_index) {
120 result->CopyFrom(this, insertion_index, insertion_index + 1, witness);
121 }
122
123 return result;
124 }
125
126
127 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/transitions.h ('k') | src/transitions-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698