Skip to content

Commit

Permalink
Bug 1515533 - Bump smallvec and smallbitvec r=emilio
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D15052

--HG--
extra : moz-landing-system : lando
  • Loading branch information
heycam committed Dec 20, 2018
1 parent f893226 commit 99f949e
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 27 deletions.
30 changes: 15 additions & 15 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 servo/components/malloc_size_of/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ selectors = { path = "../selectors" }
serde = { version = "1.0.27", optional = true }
serde_bytes = { version = "0.10", optional = true }
servo_arc = { path = "../servo_arc" }
smallbitvec = "2.1.0"
smallbitvec = "2.3.0"
smallvec = "0.6"
string_cache = { version = "0.7", optional = true }
thin-slice = "0.1.0"
Expand Down
4 changes: 2 additions & 2 deletions servo/components/style/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ serde = {version = "1.0", optional = true, features = ["derive"]}
servo_arc = { path = "../servo_arc" }
servo_atoms = {path = "../atoms", optional = true}
servo_config = {path = "../config", optional = true}
smallbitvec = "2.1.1"
smallvec = "0.6"
smallbitvec = "2.3.0"
smallvec = "0.6.6"
string_cache = { version = "0.7", optional = true }
style_derive = {path = "../style_derive"}
style_traits = {path = "../style_traits"}
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/smallbitvec/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"files":{"Cargo.toml":"0923f01dc65f779c739001ea75778f7883ab6eea3a8082cb969a5d0e70304ed6","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"daa94322de7eab889e055932396160395bd8e3af82f56ae8c419d3049111da72","README.md":"4ac9c9b88726f6bcc3b454d61ce75a8224bd430584b765e304be9aa21815c327","benches/bench.rs":"9691c531845f2741bcb6485641ee3fd3e39980925ec6e5f716464e94fd5adfd0","src/lib.rs":"f892034f32f48e60f0e22fad45faa7a230b0f119ef78f68b6ba3cdb525ea649b","src/tests.rs":"1d92b1cf9660293664bcee3be22c40859603dece4502cedcf53e0b0301683d7e"},"package":"5c63726029f0069f88467873e47f392575f28f9f16b72ac65465263db4b3a13c"}
{"files":{"Cargo.toml":"04bb81776575ff83d73fd27b8b8a1c3db8ecf9696c30a9a7def7dc79158914bd","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"daa94322de7eab889e055932396160395bd8e3af82f56ae8c419d3049111da72","README.md":"4ac9c9b88726f6bcc3b454d61ce75a8224bd430584b765e304be9aa21815c327","benches/bench.rs":"9691c531845f2741bcb6485641ee3fd3e39980925ec6e5f716464e94fd5adfd0","src/lib.rs":"f05c517845d5836ce3900a883be3ee2f91c38af9dac5defaae7fdce37f0bb6df","src/tests.rs":"5105852aa97ca9569adba05e99b7080b1c6970d2fe9b9eff43beaa4bbe371838"},"package":"1764fe2b30ee783bfe3b9b37b2649d8d590b3148bb12e0079715d4d5c673562e"}
2 changes: 1 addition & 1 deletion third_party/rust/smallbitvec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

[package]
name = "smallbitvec"
version = "2.1.1"
version = "2.3.0"
authors = ["Matt Brubeck <[email protected]>"]
description = "A bit vector optimized for size and inline storage"
documentation = "https://docs.rs/smallbitvec"
Expand Down
112 changes: 112 additions & 0 deletions third_party/rust/smallbitvec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ fn buffer_len(cap: usize) -> usize {
(cap + bits_per_storage() - 1) / bits_per_storage()
}

/// A typed representation of a `SmallBitVec`'s internal storage.
///
/// The layout of the data inside both enum variants is a private implementation detail.
pub enum InternalStorage {
/// The internal representation of a `SmallBitVec` that has not spilled to a
/// heap allocation.
Inline(usize),

/// The contents of the heap allocation of a spilled `SmallBitVec`.
Spilled(Box<[usize]>),
}

impl SmallBitVec {
/// Create an empty vector.
#[inline]
Expand Down Expand Up @@ -468,6 +480,8 @@ impl SmallBitVec {
}

/// Returns true if all the bits in the vec are set to zero/false.
///
/// On an empty vector, returns true.
#[inline]
pub fn all_false(&self) -> bool {
let mut len = self.len();
Expand Down Expand Up @@ -498,6 +512,8 @@ impl SmallBitVec {
}

/// Returns true if all the bits in the vec are set to one/true.
///
/// On an empty vector, returns true.
#[inline]
pub fn all_true(&self) -> bool {
let mut len = self.len();
Expand Down Expand Up @@ -527,6 +543,42 @@ impl SmallBitVec {
}
}

/// Shorten the vector, keeping the first `len` elements and dropping the rest.
///
/// If `len` is greater than or equal to the vector's current length, this has no
/// effect.
///
/// This does not re-allocate.
pub fn truncate(&mut self, len: usize) {
unsafe {
if len < self.len() {
self.set_len(len);
}
}
}

/// Resizes the vector so that its length is equal to `len`.
///
/// If `len` is less than the current length, the vector simply truncated.
///
/// If `len` is greater than the current length, `value` is appended to the
/// vector until its length equals `len`.
pub fn resize(&mut self, len: usize, value: bool) {
let old_len = self.len();

if len > old_len {
unsafe {
self.reallocate(len);
self.set_len(len);
for i in old_len..len {
self.set(i, value);
}
}
} else {
self.truncate(len);
}
}

/// Resize the vector to have capacity for at least `cap` bits.
///
/// `cap` must be at least as large as the length of the vector.
Expand Down Expand Up @@ -575,6 +627,66 @@ impl SmallBitVec {
}
}

/// Converts this `SmallBitVec` into its internal representation.
///
/// The layout of the data inside both enum variants is a private implementation detail.
#[inline]
pub fn into_storage(self) -> InternalStorage {
if self.is_heap() {
let alloc_len = header_len() + self.header().buffer_len;
let ptr = self.header_raw() as *mut Storage;
let slice = unsafe { Box::from_raw(slice::from_raw_parts_mut(ptr, alloc_len)) };
forget(self);
InternalStorage::Spilled(slice)
} else {
InternalStorage::Inline(self.data)
}
}

/// Creates a `SmallBitVec` directly from the internal storage of another
/// `SmallBitVec`.
///
/// # Safety
///
/// This is highly unsafe. `storage` needs to have been previously generated
/// via `SmallBitVec::into_storage` (at least, it's highly likely to be
/// incorrect if it wasn't.) Violating this may cause problems like corrupting the
/// allocator's internal data structures.
///
/// # Examples
///
/// ```
/// # use smallbitvec::{InternalStorage, SmallBitVec};
///
/// fn main() {
/// let v = SmallBitVec::from_elem(200, false);
///
/// // Get the internal representation of the SmallBitVec.
/// // unless we transfer its ownership somewhere else.
/// let storage = v.into_storage();
///
/// /// Make a copy of the SmallBitVec's data.
/// let cloned_storage = match storage {
/// InternalStorage::Spilled(vs) => InternalStorage::Spilled(vs.clone()),
/// inline => inline,
/// };
///
/// /// Create a new SmallBitVec from the coped storage.
/// let v = unsafe { SmallBitVec::from_storage(cloned_storage) };
/// }
/// ```
pub unsafe fn from_storage(storage: InternalStorage) -> SmallBitVec {
match storage {
InternalStorage::Inline(data) => SmallBitVec { data },
InternalStorage::Spilled(vs) => {
let ptr = Box::into_raw(vs);
SmallBitVec {
data: (ptr as *mut usize as usize) | HEAP_FLAG,
}
}
}
}

/// If the rightmost bit is set, then we treat it as inline storage.
#[inline]
fn is_inline(&self) -> bool {
Expand Down
52 changes: 52 additions & 0 deletions third_party/rust/smallbitvec/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,55 @@ fn eq() {
assert_ne!(sbvec![true; 400], sbvec![true; 401]);
assert_ne!(sbvec![false; 401], sbvec![false; 400]);
}

#[test]
fn truncate_inline() {
let mut v = sbvec![false, true, false, false, true];
v.truncate(10);
assert_eq!(v.len(), 5);
v.truncate(3);
assert_eq!(v, sbvec![false, true, false]);
v.truncate(0);
assert_eq!(v, sbvec![]);
}

#[test]
fn truncate_large() {
let mut v = SmallBitVec::from_elem(256, false);
v.set(2, true);
v.set(100, true);
v.set(255, true);
v.truncate(500);
assert_eq!(v.len(), 256);
v.truncate(150);
assert_eq!(v.len(), 150);
assert_eq!(v.get(0).unwrap(), false);
assert_eq!(v.get(99).unwrap(), false);
assert_eq!(v.get(100).unwrap(), true);
assert_eq!(v.get(101).unwrap(), false);
assert_eq!(v.get(149).unwrap(), false);
v.truncate(5);
assert_eq!(v.len(), 5);
assert_eq!(v, sbvec![false, false, true, false, false]);
}

#[test]
fn resize() {
let mut v = sbvec![false, true, false, false, true];
v.resize(3, false);
assert_eq!(v, sbvec![false, true, false]);
v.resize(8, true);
assert_eq!(v, sbvec![false, true, false, true, true, true, true, true]);
v.resize(100, false);
assert_eq!(v.len(), 100);
assert_eq!(v.get(0).unwrap(), false);
assert_eq!(v.get(1).unwrap(), true);
assert_eq!(v.get(2).unwrap(), false);
assert_eq!(v.get(3).unwrap(), true);
assert_eq!(v.get(4).unwrap(), true);
assert_eq!(v.get(7).unwrap(), true);
assert_eq!(v.get(8).unwrap(), false);
assert_eq!(v.get(9).unwrap(), false);
assert_eq!(v.get(98).unwrap(), false);
assert_eq!(v.get(99).unwrap(), false);
}
2 changes: 1 addition & 1 deletion third_party/rust/smallvec/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"files":{"Cargo.toml":"7d0640e384cf1d81593bd049f6bf5b1dcf129db200f4f21b18c06b6bdb5d67a3","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0b28172679e0009b655da42797c03fd163a3379d5cfa67ba1f1655e974a2a1a9","README.md":"1bc64a621160a291c86b8770f3eeaa45a31c31d91c2a071f39981c14fdacb035","benches/bench.rs":"9dca7122a3dcb2c099e49807e4d3b8f01d9220e2b3db0a54e9901ee74392866f","lib.rs":"513374844e0fc3bc332f5172de3a604acab160e02f576f7d9eaebe64149588a9"},"package":"153ffa32fd170e9944f7e0838edf824a754ec4c1fc64746fcc9fe1f8fa602e5d"}
{"files":{"Cargo.toml":"6dfd8546c3b51b9b1cca1c1c52996e8bcaa899ee5edba5b8b077f0e111d962ab","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0b28172679e0009b655da42797c03fd163a3379d5cfa67ba1f1655e974a2a1a9","README.md":"38eef4ebde6fe6effa12a2dbca3bd69d6446b2935f19a329ac4926f1cb2e5013","benches/bench.rs":"9dca7122a3dcb2c099e49807e4d3b8f01d9220e2b3db0a54e9901ee74392866f","lib.rs":"b30f38a737a71c82237e5dfc45bcfe23faf894ef22de9350f302a9603d20ac0f"},"package":"622df2d454c29a4d89b30dc3b27b42d7d90d6b9e587dbf8f67652eb7514da484"}
5 changes: 3 additions & 2 deletions third_party/rust/smallvec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

[package]
name = "smallvec"
version = "0.6.5"
version = "0.6.6"
authors = ["Simon Sapin <[email protected]>"]
description = "'Small vector' optimization: store up to a small number of items on the stack"
documentation = "http://doc.servo.org/smallvec/"
documentation = "https://doc.servo.org/smallvec/"
readme = "README.md"
keywords = ["small", "vec", "vector", "stack", "no_std"]
categories = ["data-structures"]
Expand All @@ -36,5 +36,6 @@ version = "1.0.1"

[features]
default = ["std"]
specialization = []
std = []
union = []
2 changes: 1 addition & 1 deletion third_party/rust/smallvec/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rust-smallvec
=============

[Documentation](http://docs.rs/smallvec/)
[Documentation](https://docs.rs/smallvec/)

[Release notes](https://github.com/servo/rust-smallvec/releases)

Expand Down
Loading

0 comments on commit 99f949e

Please sign in to comment.