Skip to content

Commit

Permalink
use deserialize_from for faster deserialization
Browse files Browse the repository at this point in the history
This soft-forks serde_derive to add a deserialize_from derivation for
repr(u8) enums.
  • Loading branch information
Gankra committed Dec 6, 2017
1 parent ebfd15b commit ce71b22
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
26 changes: 20 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Expand Up @@ -8,3 +8,7 @@ members = [
[profile.release]
debug = true
panic = "abort"

[replace]
"serde:1.0.23" = { git = "https://github.com/gankro/serde", branch = "deserialize_from_enums3" }
"serde_derive:1.0.23" = { git = "https://github.com/gankro/serde", branch = "deserialize_from_enums3", feature="deserialize_from" }
2 changes: 1 addition & 1 deletion webrender_api/Cargo.toml
Expand Up @@ -17,7 +17,7 @@ byteorder = "1.2.1"
euclid = "0.15"
ipc-channel = {version = "0.9", optional = true}
serde = { version = "1.0.23", features = ["rc", "derive"] }
serde_derive = { version = "1.0.23" }
serde_derive = { version = "1.0.23", features = ["deserialize_from"] }
time = "0.1"

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
1 change: 1 addition & 0 deletions webrender_api/src/display_item.rs
Expand Up @@ -88,6 +88,7 @@ impl LayerPrimitiveInfo {
pub type LayoutPrimitiveInfo = PrimitiveInfo<LayoutPixel>;
pub type LayerPrimitiveInfo = PrimitiveInfo<LayerPixel>;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum SpecificDisplayItem {
Clip(ClipDisplayItem),
Expand Down
8 changes: 6 additions & 2 deletions webrender_api/src/display_list.rs
Expand Up @@ -225,8 +225,12 @@ impl<'a> BuiltDisplayListIter<'a> {
return None;
}

self.cur_item = bincode::deserialize_from(&mut UnsafeReader::new(&mut self.data), bincode::Infinite)
.expect("MEH: malicious process?");
{
let reader = bincode::read_types::IoReader::new(UnsafeReader::new(&mut self.data));
let mut deserializer = bincode::Deserializer::new(reader, bincode::Infinite);
self.cur_item.deserialize_from(&mut deserializer)
.expect("MEH: malicious process?");
}

match self.cur_item.item {
SetGradientStops => {
Expand Down

0 comments on commit ce71b22

Please sign in to comment.