Auto merge of #10983 - notriddle:no_alloc_sort_display, r=mbrubeck

Minor reduction in the amount of allocation display list building does

Use `mem::replace` to perform the lifetime-trick without allocating a whole new buffer.

(An older of this switched from the built-in heapsort to a non-allocating introsort. Unfortunately, introsort is not a stable sorting algorithm, and the display list system relies on it being stable.)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10983)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-05-03 23:51:53 -07:00
commit 2e849b7064

View file

@ -37,6 +37,7 @@ use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::hash::{BuildHasherDefault, Hash}; use std::hash::{BuildHasherDefault, Hash};
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{border_style, filter, image_rendering, mix_blend_mode}; use style::computed_values::{border_style, filter, image_rendering, mix_blend_mode};
@ -246,8 +247,7 @@ impl DisplayList {
} }
fn sort(&mut self) { fn sort(&mut self) {
let mut list = Vec::new(); let mut list = mem::replace(&mut self.list, Vec::new());
list.append(&mut self.list);
list.sort_by(|a, b| { list.sort_by(|a, b| {
if a.base().stacking_context_id == b.base().stacking_context_id { if a.base().stacking_context_id == b.base().stacking_context_id {
@ -256,7 +256,7 @@ impl DisplayList {
self.get_offset_for_item(a).cmp(&self.get_offset_for_item(b)) self.get_offset_for_item(a).cmp(&self.get_offset_for_item(b))
}); });
self.list.append(&mut list); mem::replace(&mut self.list, list);
} }
pub fn print(&self) { pub fn print(&self) {