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

Unified Diff: runtime/vm/native_arguments.h

Issue 25062003: - Add special access for receiver as it is a frequently used operation (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/native_arguments.h
===================================================================
--- runtime/vm/native_arguments.h (revision 28025)
+++ runtime/vm/native_arguments.h (working copy)
@@ -87,46 +87,29 @@
Isolate* isolate() const { return isolate_; }
int ArgCount() const { return ArgcBits::decode(argc_tag_); }
- // Returns true if the arguments are those of an instance function call.
- bool ToInstanceFunction() const {
- return InstanceFunctionBit::decode(argc_tag_);
- }
-
- // Returns true if the arguments are those of a closure function call.
- bool ToClosureFunction() const {
- return ClosureFunctionBit::decode(argc_tag_);
- }
-
RawObject* ArgAt(int index) const {
ASSERT((index >= 0) && (index < ArgCount()));
return (*argv_)[-index];
}
- int NumHiddenArgs() const {
- // For static closure functions, the closure at index 0 is hidden.
- // In the instance closure function case, the receiver is accessed from
- // the context and the closure at index 0 is hidden, so the apparent
- // argument count remains unchanged.
- if (ToClosureFunction() && !ToInstanceFunction()) {
- return 1;
- }
- return 0;
+ int NativeArgCount() const {
+ int function_bits = FunctionBits::decode(argc_tag_);
+ return ArgCount() - NumHiddenArgs(function_bits);
}
- int NativeArgCount() const {
- return ArgCount() - NumHiddenArgs();
+ RawObject* NativeReceiver() const {
+ ASSERT(ToInstanceFunction());
+ return NativeArg0();
}
RawObject* NativeArgAt(int index) const {
ASSERT((index >= 0) && (index < NativeArgCount()));
- if ((index == 0) && ToClosureFunction() && ToInstanceFunction()) {
- // Retrieve the receiver from the context.
- const Context& context = Context::Handle(isolate_->top_context());
- return context.At(0);
- } else {
- const int actual_index = index + NumHiddenArgs();
- return ArgAt(actual_index);
+ if (index == 0) {
+ return NativeArg0();
}
+ int function_bits = FunctionBits::decode(argc_tag_);
+ const int actual_index = index + NumHiddenArgs(function_bits);
+ return ArgAt(actual_index);
}
void SetReturn(const Object& value) const {
@@ -162,21 +145,29 @@
ASSERT(function.is_native());
ASSERT(!function.IsConstructor()); // Not supported.
int tag = ArgcBits::encode(function.NumParameters());
- tag = InstanceFunctionBit::update(!function.is_static(), tag);
- tag = ClosureFunctionBit::update(function.IsClosureFunction(), tag);
- return tag;
+ int function_bits = 0;
+ if (!function.is_static()) {
+ function_bits |= kInstanceFunctionBit;
+ }
+ if (function.IsClosureFunction()) {
+ function_bits |= kClosureFunctionBit;
+ }
+ return FunctionBits::update(function_bits, tag);
}
private:
+ enum {
+ kInstanceFunctionBit = 1,
+ kClosureFunctionBit = 2,
+ };
enum ArgcTagBits {
kArgcBit = 0,
kArgcSize = 24,
- kInstanceFunctionBit = 24,
- kClosureFunctionBit = 25,
+ kFunctionBit = 24,
+ kFunctionSize = 2,
};
class ArgcBits : public BitField<int, kArgcBit, kArgcSize> {};
- class InstanceFunctionBit : public BitField<bool, kInstanceFunctionBit, 1> {};
- class ClosureFunctionBit : public BitField<bool, kClosureFunctionBit, 1> {};
+ class FunctionBits : public BitField<int, kFunctionBit, kFunctionSize> {};
friend class Api;
friend class BootstrapNatives;
friend class Simulator;
@@ -189,6 +180,37 @@
*retval_ = value;
}
+ // Returns true if the arguments are those of an instance function call.
+ bool ToInstanceFunction() const {
+ return (FunctionBits::decode(argc_tag_) & kInstanceFunctionBit);
+ }
+
+ // Returns true if the arguments are those of a closure function call.
+ bool ToClosureFunction() const {
+ return (FunctionBits::decode(argc_tag_) & kClosureFunctionBit);
+ }
+
+ int NumHiddenArgs(int function_bits) const {
+ // For static closure functions, the closure at index 0 is hidden.
+ // In the instance closure function case, the receiver is accessed from
+ // the context and the closure at index 0 is hidden, so the apparent
+ // argument count remains unchanged.
+ if (function_bits == kClosureFunctionBit) {
+ return 1;
+ }
+ return 0;
+ }
+
+ RawObject* NativeArg0() const {
+ int function_bits = FunctionBits::decode(argc_tag_);
+ if (function_bits == (kClosureFunctionBit | kInstanceFunctionBit)) {
+ // Retrieve the receiver from the context.
+ const Context& context = Context::Handle(isolate_->top_context());
+ return context.At(0);
+ }
+ return ArgAt(NumHiddenArgs(function_bits));
+ }
+
Isolate* isolate_; // Current isolate pointer.
int argc_tag_; // Encodes argument count and invoked native call type.
RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call.
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698