aboutsummaryrefslogtreecommitdiff
path: root/src/timer_wrap.cc
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2014-09-29 10:13:35 -0700
committerTrevor Norris <trev.norris@gmail.com>2014-09-29 10:13:35 -0700
commitde312cfd7c21c551d497af49aa981e07ed2f5ba3 (patch)
tree565139d8708abb0a8ebf2d71b0b97b9ef04fdf2f /src/timer_wrap.cc
parent2122a77f5177a039b80403a3772fdd14323e158a (diff)
downloadandroid-node-v8-de312cfd7c21c551d497af49aa981e07ed2f5ba3.tar.gz
android-node-v8-de312cfd7c21c551d497af49aa981e07ed2f5ba3.tar.bz2
android-node-v8-de312cfd7c21c551d497af49aa981e07ed2f5ba3.zip
timer_wrap: remove HandleScopes, check return size
Calls from JS to C++ have an implicit HandleScope. So there is no need to instantiate a new HandleScope in these basic cases. Check if the returned int64_t is an SMI and cast the return value to uint32_t instead of a double. Prevents needing to box the return value, and saves a small amount of execution time. Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'src/timer_wrap.cc')
-rw-r--r--src/timer_wrap.cc23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc
index 099a54ec95..71e6a61343 100644
--- a/src/timer_wrap.cc
+++ b/src/timer_wrap.cc
@@ -97,8 +97,6 @@ class TimerWrap : public HandleWrap {
}
static void Start(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
- HandleScope scope(env->isolate());
TimerWrap* wrap = Unwrap<TimerWrap>(args.Holder());
int64_t timeout = args[0]->IntegerValue();
@@ -108,8 +106,6 @@ class TimerWrap : public HandleWrap {
}
static void Stop(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
- HandleScope scope(env->isolate());
TimerWrap* wrap = Unwrap<TimerWrap>(args.Holder());
int err = uv_timer_stop(&wrap->handle_);
@@ -117,8 +113,6 @@ class TimerWrap : public HandleWrap {
}
static void Again(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
- HandleScope scope(env->isolate());
TimerWrap* wrap = Unwrap<TimerWrap>(args.Holder());
int err = uv_timer_again(&wrap->handle_);
@@ -126,8 +120,6 @@ class TimerWrap : public HandleWrap {
}
static void SetRepeat(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
- HandleScope scope(env->isolate());
TimerWrap* wrap = Unwrap<TimerWrap>(args.Holder());
int64_t repeat = args[0]->IntegerValue();
@@ -136,12 +128,13 @@ class TimerWrap : public HandleWrap {
}
static void GetRepeat(const FunctionCallbackInfo<Value>& args) {
- Environment* env = Environment::GetCurrent(args.GetIsolate());
- HandleScope scope(env->isolate());
TimerWrap* wrap = Unwrap<TimerWrap>(args.Holder());
int64_t repeat = uv_timer_get_repeat(&wrap->handle_);
- args.GetReturnValue().Set(static_cast<double>(repeat));
+ if (repeat <= 0xfffffff)
+ args.GetReturnValue().Set(static_cast<uint32_t>(repeat));
+ else
+ args.GetReturnValue().Set(static_cast<double>(repeat));
}
static void OnTimeout(uv_timer_t* handle) {
@@ -153,11 +146,13 @@ class TimerWrap : public HandleWrap {
}
static void Now(const FunctionCallbackInfo<Value>& args) {
- HandleScope handle_scope(args.GetIsolate());
Environment* env = Environment::GetCurrent(args.GetIsolate());
uv_update_time(env->event_loop());
- double now = static_cast<double>(uv_now(env->event_loop()));
- args.GetReturnValue().Set(now);
+ uint64_t now = uv_now(env->event_loop());
+ if (now <= 0xfffffff)
+ args.GetReturnValue().Set(static_cast<uint32_t>(now));
+ else
+ args.GetReturnValue().Set(static_cast<double>(now));
}
uv_timer_t handle_;