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

Unified Diff: runtime/lib/mirrors.cc

Issue 19856003: Inline create parameter mirror list functionality. (Closed) Base URL: https://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/object.h » ('j') | runtime/vm/object.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/mirrors.cc
diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc
index 790705a11158304af0057734caf38f472c3b9573..b0613bd40ddaead79ebce0d503193ef2d5b0257c 100644
--- a/runtime/lib/mirrors.cc
+++ b/runtime/lib/mirrors.cc
@@ -235,47 +235,39 @@ static Dart_Handle UnwrapMirror(Dart_Handle mirror) {
static Dart_Handle CreateLazyMirror(Dart_Handle target);
-static Dart_Handle CreateParameterMirrorList(Dart_Handle func) {
+static RawInstance* CreateParameterMirrorList(const Function& func) {
+ const intptr_t param_cnt = func.num_fixed_parameters() -
Michael Lippautz (Google) 2013/07/23 18:41:46 num_fixed_parameters() includes the implicit ones
+ func.NumImplicitParameters() +
+ func.NumOptionalParameters();
+ const Array& results = Array::Handle(Array::New(param_cnt));
+ const Array& args = Array::Handle(Array::New(3));
+ const MirrorReference& reflectee = MirrorReference::Handle(
+ MirrorReference::New(func));
+ Smi& pos = Smi::Handle();
+ Instance& param = Instance::Handle();
+ for (intptr_t i = 0; i < param_cnt; ++i) {
+ pos ^= Smi::New(i);
+ args.SetAt(0, reflectee);
siva 2013/07/23 21:44:58 This line can be hoisted out of the loop.
Michael Lippautz (Google) 2013/07/23 23:18:13 Done.
+ args.SetAt(1, pos);
+ args.SetAt(2, (i >= func.num_fixed_parameters()) ?
+ Bool::True() : Bool::False());
+ param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args);
Michael Lippautz (Google) 2013/07/23 18:41:46 This looks up the class each time it is invoked (l
+ results.SetAt(i, param);
+ }
+ results.MakeImmutable();
+ return results.raw();
+}
+
+
+static Dart_Handle CreateParameterMirrorListUsingApi(Dart_Handle func) {
ASSERT(Dart_IsFunction(func));
- int64_t fixed_param_count;
- int64_t opt_param_count;
- Dart_Handle result = Dart_FunctionParameterCounts(func,
- &fixed_param_count,
- &opt_param_count);
- if (Dart_IsError(result)) {
- return result;
- }
-
- int64_t param_count = fixed_param_count + opt_param_count;
- Dart_Handle parameter_list = Dart_NewList(param_count);
- if (Dart_IsError(parameter_list)) {
- return result;
- }
-
- Dart_Handle param_cls_name = NewString("_LocalParameterMirrorImpl");
- Dart_Handle param_type = Dart_GetType(MirrorLib(), param_cls_name, 0, NULL);
- if (Dart_IsError(param_type)) {
- return param_type;
- }
-
- Dart_Handle reflectee = CreateMirrorReference(func);
- for (int64_t i = 0; i < param_count; i++) {
- Dart_Handle args[] = {
- reflectee,
- Dart_NewInteger(i),
- (i >= fixed_param_count) ? Api::True() : Api::False(),
- };
- Dart_Handle param =
- Dart_New(param_type, Dart_Null(), ARRAY_SIZE(args), args);
- if (Dart_IsError(param)) {
- return param;
- }
- result = Dart_ListSetAt(parameter_list, i, param);
- if (Dart_IsError(result)) {
- return result;
- }
- }
- return parameter_list;
+ Isolate* isolate = Isolate::Current();
+ Instance& retvalue = Instance::Handle();
+ Dart_EnterScope();
Michael Lippautz (Google) 2013/07/23 18:41:46 Right now the parameter list is created eagerly wh
+ const Function& func_obj = Api::UnwrapFunctionHandle(isolate, func);
+ retvalue ^= CreateParameterMirrorList(func_obj);
+ Dart_ExitScope();
siva 2013/07/23 21:44:58 why do you need a Dart_EnterScope() / Dart_ExitSco
Michael Lippautz (Google) 2013/07/23 23:18:13 As discussed offline, we rather use a HANDLESCOPE
+ return Api::NewHandle(isolate, retvalue.raw());
}
@@ -304,7 +296,7 @@ static Dart_Handle CreateLazyMirror(Dart_Handle target) {
Dart_Handle args[] = {
CreateLazyMirror(return_type),
- CreateParameterMirrorList(sig),
+ CreateParameterMirrorListUsingApi(sig),
};
return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
} else {
@@ -583,7 +575,7 @@ static Dart_Handle CreateMethodMirrorUsingApi(Dart_Handle func,
Dart_Handle args[] = {
CreateMirrorReference(func),
owner_mirror,
- CreateParameterMirrorList(func),
+ CreateParameterMirrorListUsingApi(func),
func_obj.is_static() ? Api::True() : Api::False(),
func_obj.is_abstract() ? Api::True() : Api::False(),
func_obj.IsGetterFunction() ? Api::True() : Api::False(),
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698