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

Side by Side Diff: src/list-inl.h

Issue 10443114: Progress towards making Zones independent of Isolates and Threads. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix nits and rebase on current bleeding_edge 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/list.h ('k') | src/lithium.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 17 matching lines...) Expand all
28 #ifndef V8_LIST_INL_H_ 28 #ifndef V8_LIST_INL_H_
29 #define V8_LIST_INL_H_ 29 #define V8_LIST_INL_H_
30 30
31 #include "list.h" 31 #include "list.h"
32 32
33 namespace v8 { 33 namespace v8 {
34 namespace internal { 34 namespace internal {
35 35
36 36
37 template<typename T, class P> 37 template<typename T, class P>
38 void List<T, P>::Add(const T& element) { 38 void List<T, P>::Add(const T& element, P alloc) {
39 if (length_ < capacity_) { 39 if (length_ < capacity_) {
40 data_[length_++] = element; 40 data_[length_++] = element;
41 } else { 41 } else {
42 List<T, P>::ResizeAdd(element); 42 List<T, P>::ResizeAdd(element, alloc);
43 } 43 }
44 } 44 }
45 45
46 46
47 template<typename T, class P> 47 template<typename T, class P>
48 void List<T, P>::AddAll(const List<T, P>& other) { 48 void List<T, P>::AddAll(const List<T, P>& other, P alloc) {
49 AddAll(other.ToVector()); 49 AddAll(other.ToVector(), alloc);
50 } 50 }
51 51
52 52
53 template<typename T, class P> 53 template<typename T, class P>
54 void List<T, P>::AddAll(const Vector<T>& other) { 54 void List<T, P>::AddAll(const Vector<T>& other, P alloc) {
55 int result_length = length_ + other.length(); 55 int result_length = length_ + other.length();
56 if (capacity_ < result_length) Resize(result_length); 56 if (capacity_ < result_length) Resize(result_length, alloc);
57 for (int i = 0; i < other.length(); i++) { 57 for (int i = 0; i < other.length(); i++) {
58 data_[length_ + i] = other.at(i); 58 data_[length_ + i] = other.at(i);
59 } 59 }
60 length_ = result_length; 60 length_ = result_length;
61 } 61 }
62 62
63 63
64 // Use two layers of inlining so that the non-inlined function can 64 // Use two layers of inlining so that the non-inlined function can
65 // use the same implementation as the inlined version. 65 // use the same implementation as the inlined version.
66 template<typename T, class P> 66 template<typename T, class P>
67 void List<T, P>::ResizeAdd(const T& element) { 67 void List<T, P>::ResizeAdd(const T& element, P alloc) {
68 ResizeAddInternal(element); 68 ResizeAddInternal(element, alloc);
69 } 69 }
70 70
71 71
72 template<typename T, class P> 72 template<typename T, class P>
73 void List<T, P>::ResizeAddInternal(const T& element) { 73 void List<T, P>::ResizeAddInternal(const T& element, P alloc) {
74 ASSERT(length_ >= capacity_); 74 ASSERT(length_ >= capacity_);
75 // Grow the list capacity by 100%, but make sure to let it grow 75 // Grow the list capacity by 100%, but make sure to let it grow
76 // even when the capacity is zero (possible initial case). 76 // even when the capacity is zero (possible initial case).
77 int new_capacity = 1 + 2 * capacity_; 77 int new_capacity = 1 + 2 * capacity_;
78 // Since the element reference could be an element of the list, copy 78 // Since the element reference could be an element of the list, copy
79 // it out of the old backing storage before resizing. 79 // it out of the old backing storage before resizing.
80 T temp = element; 80 T temp = element;
81 Resize(new_capacity); 81 Resize(new_capacity, alloc);
82 data_[length_++] = temp; 82 data_[length_++] = temp;
83 } 83 }
84 84
85 85
86 template<typename T, class P> 86 template<typename T, class P>
87 void List<T, P>::Resize(int new_capacity) { 87 void List<T, P>::Resize(int new_capacity, P alloc) {
88 T* new_data = List<T, P>::NewData(new_capacity); 88 T* new_data = NewData(new_capacity, alloc);
89 memcpy(new_data, data_, capacity_ * sizeof(T)); 89 memcpy(new_data, data_, capacity_ * sizeof(T));
90 List<T, P>::DeleteData(data_); 90 List<T, P>::DeleteData(data_);
91 data_ = new_data; 91 data_ = new_data;
92 capacity_ = new_capacity; 92 capacity_ = new_capacity;
93 } 93 }
94 94
95 95
96 template<typename T, class P> 96 template<typename T, class P>
97 Vector<T> List<T, P>::AddBlock(T value, int count) { 97 Vector<T> List<T, P>::AddBlock(T value, int count, P alloc) {
98 int start = length_; 98 int start = length_;
99 for (int i = 0; i < count; i++) Add(value); 99 for (int i = 0; i < count; i++) Add(value, alloc);
100 return Vector<T>(&data_[start], count); 100 return Vector<T>(&data_[start], count);
101 } 101 }
102 102
103 103
104 template<typename T, class P> 104 template<typename T, class P>
105 void List<T, P>::InsertAt(int index, const T& elm) { 105 void List<T, P>::InsertAt(int index, const T& elm, P alloc) {
106 ASSERT(index >= 0 && index <= length_); 106 ASSERT(index >= 0 && index <= length_);
107 Add(elm); 107 Add(elm, alloc);
108 for (int i = length_ - 1; i > index; --i) { 108 for (int i = length_ - 1; i > index; --i) {
109 data_[i] = data_[i - 1]; 109 data_[i] = data_[i - 1];
110 } 110 }
111 data_[index] = elm; 111 data_[index] = elm;
112 } 112 }
113 113
114 114
115 template<typename T, class P> 115 template<typename T, class P>
116 T List<T, P>::Remove(int i) { 116 T List<T, P>::Remove(int i) {
117 T element = at(i); 117 T element = at(i);
(...skipping 12 matching lines...) Expand all
130 if (data_[i] == elm) { 130 if (data_[i] == elm) {
131 Remove(i); 131 Remove(i);
132 return true; 132 return true;
133 } 133 }
134 } 134 }
135 return false; 135 return false;
136 } 136 }
137 137
138 138
139 template<typename T, class P> 139 template<typename T, class P>
140 void List<T, P>::Allocate(int length) { 140 void List<T, P>::Allocate(int length, P allocator) {
141 DeleteData(data_); 141 DeleteData(data_);
142 Initialize(length); 142 Initialize(length, allocator);
143 length_ = length; 143 length_ = length;
144 } 144 }
145 145
146 146
147 template<typename T, class P> 147 template<typename T, class P>
148 void List<T, P>::Clear() { 148 void List<T, P>::Clear() {
149 DeleteData(data_); 149 DeleteData(data_);
150 Initialize(0); 150 Initialize(0);
151 } 151 }
152 152
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 201
202 202
203 template<typename T, class P> 203 template<typename T, class P>
204 void List<T, P>::Sort() { 204 void List<T, P>::Sort() {
205 Sort(PointerValueCompare<T>); 205 Sort(PointerValueCompare<T>);
206 } 206 }
207 207
208 208
209 template<typename T, class P> 209 template<typename T, class P>
210 void List<T, P>::Initialize(int capacity) { 210 void List<T, P>::Initialize(int capacity, P allocator) {
211 ASSERT(capacity >= 0); 211 ASSERT(capacity >= 0);
212 data_ = (capacity > 0) ? NewData(capacity) : NULL; 212 data_ = (capacity > 0) ? NewData(capacity, allocator) : NULL;
213 capacity_ = capacity; 213 capacity_ = capacity;
214 length_ = 0; 214 length_ = 0;
215 } 215 }
216 216
217 217
218 template <typename T, typename P> 218 template <typename T, typename P>
219 int SortedListBSearch(const List<T>& list, P cmp) { 219 int SortedListBSearch(const List<T>& list, P cmp) {
220 int low = 0; 220 int low = 0;
221 int high = list.length() - 1; 221 int high = list.length() - 1;
222 while (low <= high) { 222 while (low <= high) {
(...skipping 29 matching lines...) Expand all
252 252
253 template <typename T> 253 template <typename T>
254 int SortedListBSearch(const List<T>& list, T elem) { 254 int SortedListBSearch(const List<T>& list, T elem) {
255 return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem)); 255 return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem));
256 } 256 }
257 257
258 258
259 } } // namespace v8::internal 259 } } // namespace v8::internal
260 260
261 #endif // V8_LIST_INL_H_ 261 #endif // V8_LIST_INL_H_
OLDNEW
« no previous file with comments | « src/list.h ('k') | src/lithium.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698