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

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

Issue 565513002: Optimize LocalVarDescriptor objects for functions that have no local variables (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 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 | « runtime/vm/raw_object.h ('k') | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 4
5 #include "vm/scopes.h" 5 #include "vm/scopes.h"
6 6
7 #include "vm/object.h" 7 #include "vm/object.h"
8 #include "vm/stack_frame.h" 8 #include "vm/stack_frame.h"
9 #include "vm/symbols.h" 9 #include "vm/symbols.h"
10 10
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 desc.info.end_pos = end_token_pos(); 259 desc.info.end_pos = end_token_pos();
260 ASSERT(desc.info.begin_pos <= desc.info.end_pos); 260 ASSERT(desc.info.begin_pos <= desc.info.end_pos);
261 desc.info.set_index(context_scope.ContextIndexAt(i)); 261 desc.info.set_index(context_scope.ContextIndexAt(i));
262 vars.Add(desc); 262 vars.Add(desc);
263 } 263 }
264 } 264 }
265 // Now collect all variables from local scopes. 265 // Now collect all variables from local scopes.
266 int16_t scope_id = 0; 266 int16_t scope_id = 0;
267 CollectLocalVariables(&vars, &scope_id); 267 CollectLocalVariables(&vars, &scope_id);
268 268
269 if (vars.length() == 0) {
270 return Object::empty_var_descriptors().raw();
271 }
269 const LocalVarDescriptors& var_desc = 272 const LocalVarDescriptors& var_desc =
270 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length())); 273 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length()));
271 for (int i = 0; i < vars.length(); i++) { 274 for (int i = 0; i < vars.length(); i++) {
272 var_desc.SetVar(i, *(vars[i].name), &vars[i].info); 275 var_desc.SetVar(i, *(vars[i].name), &vars[i].info);
273 } 276 }
274 return var_desc.raw(); 277 return var_desc.raw();
275 } 278 }
276 279
277 280
278 // The parser creates internal variables that start with ":" 281 // The parser creates internal variables that start with ":"
279 static bool IsInternalIdentifier(const String& str) { 282 static bool IsInternalIdentifier(const String& str) {
280 ASSERT(str.Length() > 0); 283 ASSERT(str.Length() > 0);
281 return str.CharAt(0) == ':'; 284 return str.CharAt(0) == ':';
282 } 285 }
283 286
284 287
285 // Add visible variables that are declared in this scope to vars, then 288 // Add visible variables that are declared in this scope to vars, then
286 // collect visible variables of children, followed by siblings. 289 // collect visible variables of children, followed by siblings.
287 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars, 290 void LocalScope::CollectLocalVariables(GrowableArray<VarDesc>* vars,
288 int16_t* scope_id) { 291 int16_t* scope_id) {
289 (*scope_id)++; 292 (*scope_id)++;
290 if (HasContextLevel() && 293 if (HasContextLevel() &&
291 ((parent() == NULL) || 294 ((parent() == NULL) ||
292 (!parent()->HasContextLevel()) || 295 (!parent()->HasContextLevel()) ||
293 (parent()->context_level() != context_level()))) { 296 (parent()->context_level() != context_level()))) {
294 // This is the outermost scope with a context level or this scope's 297 // This is the outermost scope with a context level or this scope's
295 // context level differs from its parent's level. 298 // context level differs from its parent's level.
296 VarDesc desc; 299 VarDesc desc;
297 desc.name = &String::Handle(); // No name. 300 desc.name = &Object::null_string(); // No name.
298 desc.info.set_kind(RawLocalVarDescriptors::kContextLevel); 301 desc.info.set_kind(RawLocalVarDescriptors::kContextLevel);
299 desc.info.scope_id = *scope_id; 302 desc.info.scope_id = *scope_id;
300 desc.info.begin_pos = begin_token_pos(); 303 desc.info.begin_pos = begin_token_pos();
301 desc.info.end_pos = end_token_pos(); 304 desc.info.end_pos = end_token_pos();
302 desc.info.set_index(context_level()); 305 desc.info.set_index(context_level());
303 vars->Add(desc); 306 vars->Add(desc);
304 } 307 }
305 for (int i = 0; i < this->variables_.length(); i++) { 308 for (int i = 0; i < this->variables_.length(); i++) {
306 LocalVariable* var = variables_[i]; 309 LocalVariable* var = variables_[i];
307 if ((var->owner() == this) && !var->is_invisible()) { 310 if ((var->owner() == this) && !var->is_invisible()) {
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 return fixed_parameter_count - (index() - kParamEndSlotFromFp); 672 return fixed_parameter_count - (index() - kParamEndSlotFromFp);
670 } else { 673 } else {
671 // Shift negative indexes so that the lowest one is 0 (they are still 674 // Shift negative indexes so that the lowest one is 0 (they are still
672 // non-positive). 675 // non-positive).
673 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); 676 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp);
674 } 677 }
675 } 678 }
676 679
677 680
678 } // namespace dart 681 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/raw_object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698