servo: Merge #17672 - Use boxed slice instead of vec for FuntionTimerCallback (from sadmansk:heap_in_box); r=jdm
authorSadman Kazi <sadman@sadmansk.com>
Tue, 11 Jul 2017 18:55:18 -0700
changeset 607440 11e51e8118a77a9d9ee0ffc656e3c69c4829b3f2
parent 607439 e4fe9862f23d76849c28283fdc7cb7c3c9f11bfb
child 607441 8a3ed839ea5fd0c7de6c2b443d616ad6e8b6f08a
push id67985
push userbmo:emilio+bugs@crisal.io
push dateWed, 12 Jul 2017 08:36:44 +0000
reviewersjdm
milestone56.0a1
servo: Merge #17672 - Use boxed slice instead of vec for FuntionTimerCallback (from sadmansk:heap_in_box); r=jdm <!-- Please describe your changes on the following line: --> Added `fn trace()` implementation for `Box<[T]>` type, and change FunctionTimerCallback to store boxed slices for heap values instead of Vector. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #17611 <!-- Either: --> - [x] These changes do not require tests <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 749891e48ec6faa14447b299c48887754872e497
servo/components/script/dom/bindings/trace.rs
servo/components/script/timers.rs
--- a/servo/components/script/dom/bindings/trace.rs
+++ b/servo/components/script/dom/bindings/trace.rs
@@ -172,16 +172,24 @@ unsafe impl<T: JSTraceable> JSTraceable 
 }
 
 unsafe impl<T: JSTraceable + ?Sized> JSTraceable for Box<T> {
     unsafe fn trace(&self, trc: *mut JSTracer) {
         (**self).trace(trc)
     }
 }
 
+unsafe impl<T: JSTraceable> JSTraceable for [T] {
+    unsafe fn trace(&self, trc: *mut JSTracer) {
+        for e in self.iter() {
+            e.trace(trc);
+        }
+    }
+}
+
 unsafe impl<T: JSTraceable + Copy> JSTraceable for Cell<T> {
     unsafe fn trace(&self, trc: *mut JSTracer) {
         self.get().trace(trc)
     }
 }
 
 unsafe impl<T: JSTraceable> JSTraceable for UnsafeCell<T> {
     unsafe fn trace(&self, trc: *mut JSTracer) {
--- a/servo/components/script/timers.rs
+++ b/servo/components/script/timers.rs
@@ -345,17 +345,17 @@ pub enum IsInterval {
 pub enum TimerCallback {
     StringTimerCallback(DOMString),
     FunctionTimerCallback(Rc<Function>),
 }
 
 #[derive(JSTraceable, Clone)]
 enum InternalTimerCallback {
     StringTimerCallback(DOMString),
-    FunctionTimerCallback(Rc<Function>, Rc<Vec<Heap<JSVal>>>),
+    FunctionTimerCallback(Rc<Function>, Rc<Box<[Heap<JSVal>]>>),
 }
 
 impl HeapSizeOf for InternalTimerCallback {
     fn heap_size_of_children(&self) -> usize {
         // FIXME: Rc<T> isn't HeapSizeOf and we can't ignore it due to #6870 and #6871
         0
     }
 }
@@ -387,17 +387,17 @@ impl JsTimers {
                 // buffer isn't reallocated (and moved) after setting the Heap values
                 let mut args = Vec::with_capacity(arguments.len());
                 for _ in 0..arguments.len() {
                     args.push(Heap::default());
                 }
                 for (i, item) in arguments.iter().enumerate() {
                     args.get_mut(i).unwrap().set(item.get());
                 }
-                InternalTimerCallback::FunctionTimerCallback(function, Rc::new(args))
+                InternalTimerCallback::FunctionTimerCallback(function, Rc::new(args.into_boxed_slice()))
             }
         };
 
         // step 2
         let JsTimerHandle(new_handle) = self.next_timer_handle.get();
         self.next_timer_handle.set(JsTimerHandle(new_handle + 1));
 
         // step 3 as part of initialize_and_schedule below