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

Side by Side Diff: runtime/lib/function.cc

Issue 2983823002: Improve hashCode for closures (Closed)
Patch Set: Error handling Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/lib/function.dart » ('j') | runtime/vm/object.cc » ('J')
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/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/native_entry.h" 10 #include "vm/native_entry.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 if ((receiver_a.raw() == receiver_b.raw()) && 61 if ((receiver_a.raw() == receiver_b.raw()) &&
62 (func_a.name() == func_b.name()) && 62 (func_a.name() == func_b.name()) &&
63 (func_a.Owner() == func_b.Owner())) { 63 (func_a.Owner() == func_b.Owner())) {
64 return Bool::True().raw(); 64 return Bool::True().raw();
65 } 65 }
66 } 66 }
67 } 67 }
68 return Bool::False().raw(); 68 return Bool::False().raw();
69 } 69 }
70 70
71 DEFINE_NATIVE_ENTRY(Closure_hashCode, 1) { 71 DEFINE_NATIVE_ENTRY(Closure_computeHash, 1) {
72 const Closure& receiver = 72 const Closure& receiver =
73 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); 73 Closure::CheckedHandle(zone, arguments->NativeArgAt(0));
74 const Function& func = Function::Handle(zone, receiver.function()); 74 return Smi::New(receiver.ComputeHash());
75 return func.GetClosureHashCode();
76 } 75 }
77 76
78 DEFINE_NATIVE_ENTRY(Closure_clone, 1) { 77 DEFINE_NATIVE_ENTRY(Closure_clone, 1) {
79 const Closure& receiver = 78 const Closure& receiver =
80 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); 79 Closure::CheckedHandle(zone, arguments->NativeArgAt(0));
81 const TypeArguments& instantiator_type_arguments = 80 const TypeArguments& instantiator_type_arguments =
82 TypeArguments::Handle(zone, receiver.instantiator_type_arguments()); 81 TypeArguments::Handle(zone, receiver.instantiator_type_arguments());
83 const TypeArguments& function_type_arguments = 82 const TypeArguments& function_type_arguments =
84 TypeArguments::Handle(zone, receiver.function_type_arguments()); 83 TypeArguments::Handle(zone, receiver.function_type_arguments());
85 const Function& function = Function::Handle(zone, receiver.function()); 84 const Function& function = Function::Handle(zone, receiver.function());
86 const Context& context = Context::Handle(zone, receiver.context()); 85 const Context& context = Context::Handle(zone, receiver.context());
87 Context& cloned_context = 86 Context& cloned_context =
88 Context::Handle(zone, Context::New(context.num_variables())); 87 Context::Handle(zone, Context::New(context.num_variables()));
89 cloned_context.set_parent(Context::Handle(zone, context.parent())); 88 cloned_context.set_parent(Context::Handle(zone, context.parent()));
90 Object& instance = Object::Handle(zone); 89 Object& instance = Object::Handle(zone);
91 for (int i = 0; i < context.num_variables(); i++) { 90 for (int i = 0; i < context.num_variables(); i++) {
92 instance = context.At(i); 91 instance = context.At(i);
93 cloned_context.SetAt(i, instance); 92 cloned_context.SetAt(i, instance);
94 } 93 }
95 return Closure::New(instantiator_type_arguments, function_type_arguments, 94 return Closure::New(instantiator_type_arguments, function_type_arguments,
96 function, cloned_context); 95 function, cloned_context);
97 } 96 }
98 97
99 } // namespace dart 98 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/function.dart » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698