Skip to content

Commit

Permalink
Fixup Data impl for im::Vector
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr committed May 17, 2020
1 parent 4eba61c commit 70aba49
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion druid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fnv = "1.0.3"
instant = { version = "0.1", features = ["wasm-bindgen"] }

# Optional dependencies
im = { version = "14.0", optional = true }
im = { version = "15.0", optional = true }
usvg = { version = "0.9.0", optional = true }
image = { version = "0.23.2", optional = true }

Expand Down
19 changes: 4 additions & 15 deletions druid/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,27 +381,16 @@ impl Data for piet::Color {
}
}

//FIXME Vector::ptr_eq is not currently reliable; this is a temporary impl?
#[cfg(feature = "im")]
impl<T: Data> Data for im::Vector<T> {
fn same(&self, other: &Self) -> bool {
// for reasons outlined in https://github.com/bodil/im-rs/issues/129,
// ptr_eq always returns false for small collections. This heuristic
// falls back to using equality for collections below some threshold.
// There may be a possibility of this returning false negatives, but
// not false positives; that's an acceptable outcome.

/* this is the impl I expected to use
const INLINE_LEN: usize = 48; // bytes available before first allocation;
let inline_capacity: usize = INLINE_LEN / std::mem::size_of::<T>();
if self.len() == other.len() && self.len() <= inline_capacity {
self.iter().zip(other.iter()).all(|(a, b)| a.same(b))
// if a vec is small enough that it doesn't require an allocation
// it is 'inline'; in this case a pointer comparison is meaningless.
if self.is_inline() {
self.len() == other.len() && self.iter().zip(other.iter()).all(|(a, b)| a.same(b))
} else {
self.ptr_eq(other)
}
*/

self.len() == other.len() && self.iter().zip(other.iter()).all(|(a, b)| a.same(b))
}
}

Expand Down

0 comments on commit 70aba49

Please sign in to comment.