Skip to content

Instantly share code, notes, and snippets.

@jdm
Created November 10, 2015 21:10
Show Gist options
  • Select an option

  • Save jdm/d2f8bebe267388fd85e9 to your computer and use it in GitHub Desktop.

Select an option

Save jdm/d2f8bebe267388fd85e9 to your computer and use it in GitHub Desktop.
Avoid Clone for timer callbacks.
diff --git a/components/script/timers.rs b/components/script/timers.rs
index a7395de..1d01c91 100644
--- a/components/script/timers.rs
+++ b/components/script/timers.rs
@@ -102,7 +102,7 @@ pub enum TimerCallback {
FunctionTimerCallback(Rc<Function>),
}
-#[derive(JSTraceable, Clone)]
+#[derive(JSTraceable)]
enum InternalTimerCallback {
StringTimerCallback(DOMString),
FunctionTimerCallback(Rc<Function>, Rc<Vec<Heap<JSVal>>>),
@@ -227,33 +227,20 @@ impl ActiveTimers {
timers.pop().unwrap()
};
- let callback = timer.callback.clone();
// prep for step 6 in nested set_timeout_or_interval calls
self.nesting_level.set(timer.nesting_level);
- // step 4.3
- if timer.is_interval == IsInterval::Interval {
- let mut timer = timer;
-
- // step 7
- timer.duration = self.clamp_duration(timer.duration);
- // step 8, 9
- timer.nesting_level += 1;
- timer.next_call = base_time + timer.duration;
- self.insert_timer(timer);
- }
-
// step 14
- match callback {
- InternalTimerCallback::StringTimerCallback(code_str) => {
+ match timer.callback {
+ InternalTimerCallback::StringTimerCallback(ref code_str) => {
let proxy = this.reflector().get_jsobject();
let cx = global_object_for_js_object(proxy.get()).r().get_cx();
let mut rval = RootedValue::new(cx, UndefinedValue());
- this.evaluate_js_on_global_with_result(&code_str, rval.handle_mut());
+ this.evaluate_js_on_global_with_result(code_str, rval.handle_mut());
},
- InternalTimerCallback::FunctionTimerCallback(function, arguments) => {
+ InternalTimerCallback::FunctionTimerCallback(ref function, ref arguments) => {
let arguments: Vec<JSVal> = arguments.iter().map(|arg| arg.get()).collect();
let arguments = arguments.iter().by_ref().map(|arg| unsafe {
HandleValue::from_marked_location(arg)
@@ -263,6 +250,18 @@ impl ActiveTimers {
}
};
+ // step 4.3
+ if timer.is_interval == IsInterval::Interval {
+ let mut timer = timer;
+
+ // step 7
+ timer.duration = self.clamp_duration(timer.duration);
+ // step 8, 9
+ timer.nesting_level += 1;
+ timer.next_call = base_time + timer.duration;
+ self.insert_timer(timer);
+ }
+
self.nesting_level.set(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment