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

Unified Diff: runtime/vm/isolate.cc

Issue 1436243005: Collect closure functions in isolate (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 | « runtime/vm/isolate.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/isolate.cc
diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc
index 1a098fa78fa8b2587fea530accbbe10c0d887853..2ff605fe1a9ca736bb0997f20626a039a28286e0 100644
--- a/runtime/vm/isolate.cc
+++ b/runtime/vm/isolate.cc
@@ -1517,6 +1517,62 @@ static int MostUsedFunctionFirst(const Function* const* a,
}
+void Isolate::AddClosureFunction(const Function& function) const {
+ GrowableObjectArray& closures =
+ GrowableObjectArray::Handle(object_store()->closure_functions());
+ ASSERT(!closures.IsNull());
+ ASSERT(function.IsNonImplicitClosureFunction());
+ closures.Add(function, Heap::kOld);
+}
+
+
+// If the linear lookup turns out to be too expensive, the list
+// of closures could be maintained in a hash map, with the key
+// being the token position of the closure. There are almost no
+// collisions with this simple hash value. However, iterating over
+// all closure functions becomes more difficult, especially when
+// the list/map changes while iterating over it.
+RawFunction* Isolate::LookupClosureFunction(const Function& parent,
+ intptr_t token_pos) const {
+ const GrowableObjectArray& closures =
+ GrowableObjectArray::Handle(object_store()->closure_functions());
+ ASSERT(!closures.IsNull());
+ Function& closure = Function::Handle();
+ intptr_t num_closures = closures.Length();
+ for (intptr_t i = 0; i < num_closures; i++) {
+ closure ^= closures.At(i);
+ if ((closure.token_pos() == token_pos) &&
+ (closure.parent_function() == parent.raw())) {
+ return closure.raw();
+ }
+ }
+ return Function::null();
+}
+
+
+intptr_t Isolate::FindClosureIndex(const Function& needle) const {
+ const GrowableObjectArray& closures_array =
+ GrowableObjectArray::Handle(object_store()->closure_functions());
+ intptr_t num_closures = closures_array.Length();
+ for (intptr_t i = 0; i < num_closures; i++) {
+ if (closures_array.At(i) == needle.raw()) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+
+RawFunction* Isolate::ClosureFunctionFromIndex(intptr_t idx) const {
+ const GrowableObjectArray& closures_array =
+ GrowableObjectArray::Handle(object_store()->closure_functions());
+ if ((idx < 0) || (idx >= closures_array.Length())) {
+ return Function::null();
+ }
+ return Function::RawCast(closures_array.At(idx));
+}
+
+
static void AddFunctionsFromClass(const Class& cls,
GrowableArray<const Function*>* functions) {
const Array& class_functions = Array::Handle(cls.functions());
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698