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

Side by Side Diff: runtime/vm/kernel_binary.cc

Issue 2658693002: Removed usage of std::map and std::vector from kernel code. Issue #28064. (Closed)
Patch Set: Removed usage of std::map and std::vector from kernel code. Issue #28064. Created 3 years, 11 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
« no previous file with comments | « no previous file | runtime/vm/kernel_reader.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 (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 #if !defined(DART_PRECOMPILED_RUNTIME) 4 #if !defined(DART_PRECOMPILED_RUNTIME)
5 5
6 #include <map>
7 #include <vector>
8
9 #include "platform/globals.h" 6 #include "platform/globals.h"
10 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/growable_array.h"
11 #include "vm/kernel.h" 9 #include "vm/kernel.h"
10 #include "vm/kernel_to_il.h"
12 #include "vm/os.h" 11 #include "vm/os.h"
13 12
14 #if defined(DEBUG) 13 #if defined(DEBUG)
15 #define TRACE_READ_OFFSET() \ 14 #define TRACE_READ_OFFSET() \
16 do { \ 15 do { \
17 if (FLAG_trace_kernel_binary) reader->DumpOffset(DART_PRETTY_FUNCTION); \ 16 if (FLAG_trace_kernel_binary) reader->DumpOffset(DART_PRETTY_FUNCTION); \
18 } while (0) 17 } while (0)
19 #else 18 #else
20 #define TRACE_READ_OFFSET() 19 #define TRACE_READ_OFFSET()
21 #endif 20 #endif
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 145
147 static const int SpecializedIntLiteralBias = 3; 146 static const int SpecializedIntLiteralBias = 3;
148 147
149 148
150 template <typename T> 149 template <typename T>
151 class BlockStack { 150 class BlockStack {
152 public: 151 public:
153 BlockStack() : current_count_(0) {} 152 BlockStack() : current_count_(0) {}
154 153
155 void EnterScope() { 154 void EnterScope() {
156 variable_count_.push_back(current_count_); 155 variable_count_.Add(current_count_);
157 current_count_ = 0; 156 current_count_ = 0;
158 } 157 }
159 158
160 void LeaveScope() { 159 void LeaveScope() {
161 variables_.resize(variables_.size() - current_count_); 160 variables_.TruncateTo(variables_.length() - current_count_);
162 current_count_ = variable_count_[variable_count_.size() - 1]; 161 current_count_ = variable_count_[variable_count_.length() - 1];
163 variable_count_.pop_back(); 162 variable_count_.RemoveLast();
164 } 163 }
165 164
166 T* Lookup(int index) { 165 T* Lookup(int index) {
167 ASSERT(static_cast<unsigned>(index) < variables_.size()); 166 ASSERT(index < variables_.length());
168 return variables_[index]; 167 return variables_[index];
169 } 168 }
170 169
171 void Push(T* v) { 170 void Push(T* v) {
172 variables_.push_back(v); 171 variables_.Add(v);
173 current_count_++; 172 current_count_++;
174 } 173 }
175 174
176 void Push(List<T>* decl) { 175 void Push(List<T>* decl) {
177 for (int i = 0; i < decl->length(); i++) { 176 for (int i = 0; i < decl->length(); i++) {
178 variables_.push_back(decl[i]); 177 variables_.Add(decl[i]);
179 current_count_++; 178 current_count_++;
180 } 179 }
181 } 180 }
182 181
183 void Pop(T* decl) { 182 void Pop(T* decl) {
184 variables_.resize(variables_.size() - 1); 183 variables_.RemoveLast();
185 current_count_--; 184 current_count_--;
186 } 185 }
187 186
188 void Pop(List<T>* decl) { 187 void Pop(List<T>* decl) {
189 variables_.resize(variables_.size() - decl->length()); 188 variables_.TruncateTo(variables_.length() - decl->length());
190 current_count_ -= decl->length(); 189 current_count_ -= decl->length();
191 } 190 }
192 191
193 private: 192 private:
194 int current_count_; 193 int current_count_;
195 std::vector<T*> variables_; 194 MallocGrowableArray<T*> variables_;
196 std::vector<int> variable_count_; 195 MallocGrowableArray<int> variable_count_;
197 }; 196 };
198 197
199 198
200 template <typename T> 199 template <typename T>
201 class BlockMap { 200 class BlockMap {
202 public: 201 public:
203 BlockMap() : current_count_(0), stack_height_(0) {} 202 BlockMap() : current_count_(0), stack_height_(0) {}
204 203
205 void EnterScope() { 204 void EnterScope() {
206 variable_count_.push_back(current_count_); 205 variable_count_.Add(current_count_);
207 current_count_ = 0; 206 current_count_ = 0;
208 } 207 }
209 208
210 void LeaveScope() { 209 void LeaveScope() {
211 stack_height_ -= current_count_; 210 stack_height_ -= current_count_;
212 current_count_ = variable_count_[variable_count_.size() - 1]; 211 current_count_ = variable_count_[variable_count_.length() - 1];
213 variable_count_.pop_back(); 212 variable_count_.RemoveLast();
214 } 213 }
215 214
216 int Lookup(T* object) { 215 int Lookup(T* object) {
217 ASSERT(variables_.find(object) != variables_.end()); 216 typename MallocMap<T, int>::Pair* result = variables_.LookupPair(object);
218 if (variables_.find(object) == variables_.end()) FATAL("lookup failure"); 217 ASSERT(result != NULL);
219 return variables_[object]; 218 if (result == NULL) FATAL("lookup failure");
219 return RawPointerKeyValueTrait<T, int>::ValueOf(*result);
220 } 220 }
221 221
222 void Push(T* v) { 222 void Push(T* v) {
223 ASSERT(variables_.LookupPair(v) == NULL);
223 int index = stack_height_++; 224 int index = stack_height_++;
224 variables_[v] = index; 225 variables_.Insert(v, index);
225 current_count_++; 226 current_count_++;
226 } 227 }
227 228
228 void Set(T* v, int index) { variables_[v] = index; } 229 void Set(T* v, int index) {
230 typename MallocMap<T, int>::Pair* entry = variables_.LookupPair(v);
231 ASSERT(entry != NULL);
232 entry->value = index;
233 }
229 234
230 void Push(List<T>* decl) { 235 void Push(List<T>* decl) {
231 for (int i = 0; i < decl->length(); i++) { 236 for (int i = 0; i < decl->length(); i++) {
232 Push(decl[i]); 237 Push(decl[i]);
233 } 238 }
234 } 239 }
235 240
236 void Pop(T* v) { 241 void Pop(T* v) {
237 current_count_--; 242 current_count_--;
238 stack_height_--; 243 stack_height_--;
239 } 244 }
240 245
241 private: 246 private:
242 int current_count_; 247 int current_count_;
243 int stack_height_; 248 int stack_height_;
244 std::map<T*, int> variables_; 249 MallocMap<T, int> variables_;
245 std::vector<int> variable_count_; 250 MallocGrowableArray<int> variable_count_;
246 }; 251 };
247 252
248 253
249 template <typename T> 254 template <typename T>
250 class VariableScope { 255 class VariableScope {
251 public: 256 public:
252 explicit VariableScope(T* builder) : builder_(builder) { 257 explicit VariableScope(T* builder) : builder_(builder) {
253 builder_->variables().EnterScope(); 258 builder_->variables().EnterScope();
254 } 259 }
255 ~VariableScope() { builder_->variables().LeaveScope(); } 260 ~VariableScope() { builder_->variables().LeaveScope(); }
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 1892
1888 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, 1893 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer,
1889 intptr_t buffer_length) { 1894 intptr_t buffer_length) {
1890 kernel::Reader reader(buffer, buffer_length); 1895 kernel::Reader reader(buffer, buffer_length);
1891 return kernel::Program::ReadFrom(&reader); 1896 return kernel::Program::ReadFrom(&reader);
1892 } 1897 }
1893 1898
1894 1899
1895 } // namespace dart 1900 } // namespace dart
1896 #endif // !defined(DART_PRECOMPILED_RUNTIME) 1901 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/kernel_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698