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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 19974002: Reuse the top ApiLocalScope so that we do not allocate and free an ApiLocalScope (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/dart_api_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 25286)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -1072,9 +1072,17 @@
CHECK_ISOLATE(isolate);
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
- ApiLocalScope* new_scope = new ApiLocalScope(state->top_scope(),
- isolate->top_exit_frame_info());
- ASSERT(new_scope != NULL);
+ ApiLocalScope* new_scope = state->reusable_scope();
+ if (new_scope == NULL) {
+ new_scope = new ApiLocalScope(state->top_scope(),
+ isolate->top_exit_frame_info());
+ ASSERT(new_scope != NULL);
+ } else {
+ new_scope->Reinit(isolate,
+ state->top_scope(),
+ isolate->top_exit_frame_info());
+ state->set_reusable_scope(NULL);
+ }
state->set_top_scope(new_scope); // New scope is now the top scope.
}
@@ -1084,9 +1092,15 @@
CHECK_ISOLATE_SCOPE(isolate);
ApiState* state = isolate->api_state();
ApiLocalScope* scope = state->top_scope();
-
+ ApiLocalScope* reusable_scope = state->reusable_scope();
state->set_top_scope(scope->previous()); // Reset top scope to previous.
- delete scope; // Free up the old scope which we have just exited.
+ if (reusable_scope == NULL) {
+ scope->Reset(isolate); // Reset the old scope which we just exited.
+ state->set_reusable_scope(scope);
+ } else {
+ ASSERT(reusable_scope != scope);
+ delete scope;
+ }
}
« no previous file with comments | « no previous file | runtime/vm/dart_api_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698