Bug 1341102 - Revendor Rust dependencies.

MozReview-Commit-ID: 49YebxPbiR5
This commit is contained in:
Matt Brubeck 2017-09-15 20:52:41 -07:00
Родитель 339906d950
Коммит c538eaf174
6 изменённых файлов: 136 добавлений и 24 удалений

Просмотреть файл

@ -1 +1 @@
{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","Cargo.toml":"37dbe41747b297eb3344c056e34570fc454cbbc29593e4f147a8db41f6b401c5","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"daa94322de7eab889e055932396160395bd8e3af82f56ae8c419d3049111da72","README.md":"c7b7102e5b19a19c3a0e1cefeddb228fb57c7fac6ce91f15dada4d81d8dc2dac","benches/bench.rs":"753ab48c39c771fb0443bb150b8e7c28f0992ca8e9a725c27efbbf664e7a2f1e","src/lib.rs":"e8aa141e8d27fab0d09cf84ba8e299250cbcb814d790dffef7a6f76e316a27cd"},"package":"c1ebf4681dc284c22efb7248986bbdf8aa23c2749ea85a0107e0e787038d303e"}
{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","Cargo.toml":"d5d98ff79b139424aafbc16c69b0b163d5555c8f2587eb0545d3ca23129009be","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"daa94322de7eab889e055932396160395bd8e3af82f56ae8c419d3049111da72","README.md":"c7b7102e5b19a19c3a0e1cefeddb228fb57c7fac6ce91f15dada4d81d8dc2dac","benches/bench.rs":"6d6bc6afac8af5cfb37a672f7a1e8f9abb29b00993b85e94cd701dcd8955aabd","src/lib.rs":"e52f4408a673ce873e231d61d0059c49cb7d735335b24a797f5d071f2954b53c"},"package":"79b776f00dfe01df905fa3b2eaa1659522e99e3fc4a7b1334171622205c4bdcf"}

2
third_party/rust/smallbitvec/Cargo.toml поставляемый
Просмотреть файл

@ -12,7 +12,7 @@
[package]
name = "smallbitvec"
version = "1.0.3"
version = "1.0.6"
authors = ["Matt Brubeck <mbrubeck@limpet.net>"]
description = "A bit vector optimized for size and inline storage"
documentation = "https://docs.rs/smallbitvec"

20
third_party/rust/smallbitvec/benches/bench.rs поставляемый
Просмотреть файл

@ -207,3 +207,23 @@ fn bench_from_elem_sbv(b: &mut Bencher) {
});
b.bytes = cap as u64 / 8;
}
#[bench]
fn bench_remove_small(b: &mut Bencher) {
b.iter(|| {
let mut v = SmallBitVec::from_elem(U32_BITS as u32, false);
for _ in 0..U32_BITS {
v.remove(0);
}
});
}
#[bench]
fn bench_remove_big(b: &mut Bencher) {
b.iter(|| {
let mut v = SmallBitVec::from_elem(BENCH_BITS as u32, false);
for _ in 0..200 {
v.remove(0);
}
});
}

120
third_party/rust/smallbitvec/src/lib.rs поставляемый
Просмотреть файл

@ -44,11 +44,25 @@ fn inline_capacity() -> u32 {
inline_bits() - 2
}
/// The position of the nth bit of storage in an inline vector.
fn inline_index(n: u32) -> usize {
/// Left shift amount to access the nth bit
fn inline_shift(n: u32) -> u32 {
debug_assert!(n <= inline_capacity());
// The storage starts at the leftmost bit.
1 << (inline_bits() - 1 - n)
inline_bits() - 1 - n
}
/// An inline vector with the nth bit set.
fn inline_index(n: u32) -> usize {
1 << inline_shift(n)
}
/// An inline vector with the leftmost `n` bits set.
fn inline_ones(n: u32) -> usize {
if n == 0 {
0
} else {
!0 << (inline_bits() - n)
}
}
/// If the rightmost bit of `data` is set, then the remaining bits of `data`
@ -118,13 +132,23 @@ impl SmallBitVec {
/// Create a vector containing `len` bits, each set to `val`.
pub fn from_elem(len: u32, val: bool) -> SmallBitVec {
if len <= inline_capacity() {
return SmallBitVec {
data: if val {
inline_ones(len + 1)
} else {
inline_index(len)
}
}
}
let header_ptr = Header::new(len, len, val);
SmallBitVec {
data: (header_ptr as usize) | HEAP_FLAG
}
}
/// Create a vector with at least `cap` bits of storage.
/// Create an empty vector enough storage pre-allocated to store at least `cap` bits without
/// resizing.
pub fn with_capacity(cap: u32) -> SmallBitVec {
// Use inline storage if possible.
if cap <= inline_capacity() {
@ -260,15 +284,41 @@ impl SmallBitVec {
///
/// Panics if the index is out of bounds.
pub fn remove(&mut self, idx: u32) {
assert!(idx < self.len(), "Index {} out of bounds", idx);
let len = self.len();
assert!(idx < len, "Index {} out of bounds", idx);
for i in (idx+1)..self.len() {
if self.is_inline() {
// Shift later bits, including the length bit, toward the front.
let mask = !inline_ones(idx);
let new_vals = (self.data & mask) << 1;
self.data = (self.data & !mask) | (new_vals & mask);
} else {
let first = (idx / bits_per_storage()) as usize;
let offset = idx % bits_per_storage();
let count = buffer_len(len);
{
// Shift bits within the first storage block.
let buf = self.buffer_mut();
let mask = !0 << offset;
let new_vals = (buf[first] & mask) >> 1;
buf[first] = (buf[first] & !mask) | (new_vals & mask);
}
// Shift bits in subsequent storage blocks.
for i in (first + 1)..count {
// Move the first bit into the previous block.
let bit_idx = i as u32 * bits_per_storage();
unsafe {
let first_bit = self.get_unchecked(bit_idx);
self.set_unchecked(bit_idx - 1, first_bit);
}
// Shift the remaining bits.
self.buffer_mut()[i] >>= 1;
}
// Decrement the length.
unsafe {
let next_val = self.get_unchecked(i);
self.set_unchecked(i - 1, next_val);
self.set_len(len - 1);
}
}
self.pop();
}
/// Remove all elements from the vector, without deallocating its buffer.
@ -325,7 +375,7 @@ impl SmallBitVec {
}
if self.is_inline() {
let mask = !(inline_index(len - 1) - 1);
let mask = inline_ones(len);
self.data & mask == 0
} else {
for &storage in self.buffer() {
@ -354,7 +404,7 @@ impl SmallBitVec {
}
if self.is_inline() {
let mask = !(inline_index(len - 1) - 1);
let mask = inline_ones(len);
self.data & mask == mask
} else {
for &storage in self.buffer() {
@ -413,6 +463,16 @@ impl SmallBitVec {
}
}
/// If the vector owns a heap allocation, returns a pointer to the start of the allocation.
///
/// The layout of the data at this allocation is a private implementation detail.
pub fn heap_ptr(&self) -> Option<*const u32> {
match self.is_heap() {
true => Some((self.data & !HEAP_FLAG) as *const Storage),
false => None
}
}
/// If the rightmost bit is set, then we treat it as inline storage.
fn is_inline(&self) -> bool {
self.data & HEAP_FLAG == 0
@ -448,7 +508,7 @@ impl SmallBitVec {
}
}
fn buffer_mut(&self) -> &mut [Storage] {
fn buffer_mut(&mut self) -> &mut [Storage] {
unsafe { &mut *self.buffer_raw() }
}
@ -595,7 +655,7 @@ impl<'a> IntoIterator for &'a SmallBitVec {
}
}
/// An iterator that borrows a SmallBitVec and yields its bits as `bool` values.
/// An iterator that owns a SmallBitVec and yields its bits as `bool` values.
///
/// Returned from [`SmallBitVec::into_iter`][1].
///
@ -865,7 +925,39 @@ mod tests {
v.push(true);
v.remove(1);
assert_eq!(format!("{:?}", v), "[0, 0, 0, 1]")
assert_eq!(format!("{:?}", v), "[0, 0, 0, 1]");
v.remove(0);
assert_eq!(format!("{:?}", v), "[0, 0, 1]");
v.remove(2);
assert_eq!(format!("{:?}", v), "[0, 0]");
v.remove(1);
assert_eq!(format!("{:?}", v), "[0]");
v.remove(0);
assert_eq!(format!("{:?}", v), "[]");
}
#[test]
fn remove_big() {
let mut v = SmallBitVec::from_elem(256, false);
v.set(100, true);
v.set(255, true);
v.remove(0);
assert_eq!(v.len(), 255);
assert_eq!(v.get(0), false);
assert_eq!(v.get(99), true);
assert_eq!(v.get(100), false);
assert_eq!(v.get(253), false);
assert_eq!(v.get(254), true);
v.remove(254);
assert_eq!(v.len(), 254);
assert_eq!(v.get(0), false);
assert_eq!(v.get(99), true);
assert_eq!(v.get(100), false);
assert_eq!(v.get(253), false);
v.remove(99);
assert_eq!(v, SmallBitVec::from_elem(253, false));
}
#[test]

8
toolkit/library/gtest/rust/Cargo.lock сгенерированный
Просмотреть файл

@ -746,7 +746,7 @@ dependencies = [
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hashglobe 0.1.0",
"servo_arc 0.0.1",
"smallbitvec 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1244,7 +1244,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "smallbitvec"
version = "1.0.3"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -1299,7 +1299,7 @@ dependencies = [
"regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.19.0",
"servo_arc 0.0.1",
"smallbitvec 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"style_derive 0.0.1",
"style_traits 0.0.1",
@ -1750,7 +1750,7 @@ dependencies = [
"checksum simd 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a94d14a2ae1f1f110937de5fb69e494372560181c7e1739a097fcc2cee37ba0"
"checksum siphasher 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ffc669b726f2bc9a3bcff66e5e23b56ba6bf70e22a34c3d7b6d0b3450b65b84"
"checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23"
"checksum smallbitvec 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c1ebf4681dc284c22efb7248986bbdf8aa23c2749ea85a0107e0e787038d303e"
"checksum smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "79b776f00dfe01df905fa3b2eaa1659522e99e3fc4a7b1334171622205c4bdcf"
"checksum smallvec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8fcd03faf178110ab0334d74ca9631d77f94c8c11cc77fcb59538abf0025695d"
"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"

8
toolkit/library/rust/Cargo.lock сгенерированный
Просмотреть файл

@ -744,7 +744,7 @@ dependencies = [
"euclid 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hashglobe 0.1.0",
"servo_arc 0.0.1",
"smallbitvec 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1231,7 +1231,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "smallbitvec"
version = "1.0.3"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -1286,7 +1286,7 @@ dependencies = [
"regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.19.0",
"servo_arc 0.0.1",
"smallbitvec 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"style_derive 0.0.1",
"style_traits 0.0.1",
@ -1737,7 +1737,7 @@ dependencies = [
"checksum simd 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a94d14a2ae1f1f110937de5fb69e494372560181c7e1739a097fcc2cee37ba0"
"checksum siphasher 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ffc669b726f2bc9a3bcff66e5e23b56ba6bf70e22a34c3d7b6d0b3450b65b84"
"checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23"
"checksum smallbitvec 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c1ebf4681dc284c22efb7248986bbdf8aa23c2749ea85a0107e0e787038d303e"
"checksum smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "79b776f00dfe01df905fa3b2eaa1659522e99e3fc4a7b1334171622205c4bdcf"
"checksum smallvec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8fcd03faf178110ab0334d74ca9631d77f94c8c11cc77fcb59538abf0025695d"
"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"