Use ByteBuf for the canvas messages

The type Vec<u8> is super unefficient to work with in Serde if all you want
to represent is a simple blob.
This commit is contained in:
Anthony Ramine 2018-03-23 18:41:32 +01:00
parent 3ce3f39383
commit ce81420bef
19 changed files with 170 additions and 62 deletions

View file

@ -50,6 +50,8 @@ extern crate hashglobe;
#[cfg(feature = "servo")]
extern crate mozjs as js;
extern crate selectors;
#[cfg(feature = "servo")]
extern crate serde_bytes;
extern crate servo_arc;
extern crate smallbitvec;
extern crate smallvec;
@ -63,6 +65,8 @@ extern crate webrender_api;
#[cfg(feature = "servo")]
extern crate xml5ever;
#[cfg(feature = "servo")]
use serde_bytes::ByteBuf;
use std::hash::{BuildHasher, Hash};
use std::mem::size_of;
use std::ops::Range;
@ -300,6 +304,24 @@ impl<T: MallocSizeOf> MallocSizeOf for [T] {
}
}
#[cfg(feature = "servo")]
impl MallocShallowSizeOf for ByteBuf {
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
unsafe { ops.malloc_size_of(self.as_ptr()) }
}
}
#[cfg(feature = "servo")]
impl MallocSizeOf for ByteBuf {
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
let mut n = self.shallow_size_of(ops);
for elem in self.iter() {
n += elem.size_of(ops);
}
n
}
}
impl<T> MallocShallowSizeOf for Vec<T> {
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
unsafe { ops.malloc_size_of(self.as_ptr()) }