зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1466647: Update smallbitvec to v2.1.1. r=me
Actual code changes reviewed upstream in: https://github.com/servo/smallbitvec/pull/12 MozReview-Commit-ID: 3vKVPMovBj
This commit is contained in:
Родитель
8bdd1306a8
Коммит
e2aa5b98a1
|
@ -1139,7 +1139,7 @@ dependencies = [
|
|||
"hashglobe 0.1.0",
|
||||
"selectors 0.19.0",
|
||||
"servo_arc 0.1.1",
|
||||
"smallbitvec 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallbitvec 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -1849,7 +1849,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "smallbitvec"
|
||||
version = "2.1.0"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -1934,7 +1934,7 @@ dependencies = [
|
|||
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"selectors 0.19.0",
|
||||
"servo_arc 0.1.1",
|
||||
"smallbitvec 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallbitvec 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"style_derive 0.0.1",
|
||||
"style_traits 0.0.1",
|
||||
|
@ -2678,7 +2678,7 @@ dependencies = [
|
|||
"checksum simd 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3dd0805c7363ab51a829a1511ad24b6ed0349feaa756c4bc2f977f9f496e6673"
|
||||
"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 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "665fbc8384f961eb55c548daa2a4b1efff1f9d03b7a10f162ac6ad6a781ca966"
|
||||
"checksum smallbitvec 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c63726029f0069f88467873e47f392575f28f9f16b72ac65465263db4b3a13c"
|
||||
"checksum smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44db0ecb22921ef790d17ae13a3f6d15784183ff5f2a01aa32098c7498d2b4b9"
|
||||
"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"
|
||||
"checksum string_cache 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39cb4173bcbd1319da31faa5468a7e3870683d7a237150b0b0aaafd546f6ad12"
|
||||
|
|
|
@ -60,7 +60,7 @@ 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.0"
|
||||
smallbitvec = "2.1.1"
|
||||
smallvec = "0.6"
|
||||
string_cache = { version = "0.7", optional = true }
|
||||
style_derive = {path = "../style_derive"}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{".travis.yml":"91edce5ea2a1956399db4b17f580c8b7995af3aa9801c4314865f560c55d6d09","Cargo.toml":"b916f68b32a3896fd51b5e792b6fbefb22c45e4061f646ef38c0bd5d9f3ccc4d","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"daa94322de7eab889e055932396160395bd8e3af82f56ae8c419d3049111da72","README.md":"4ac9c9b88726f6bcc3b454d61ce75a8224bd430584b765e304be9aa21815c327","benches/bench.rs":"9691c531845f2741bcb6485641ee3fd3e39980925ec6e5f716464e94fd5adfd0","src/lib.rs":"49c8ea8ce266cbbe5fe4e32e063067f334764bf55ec957f0c56c04ffa9360b51","src/tests.rs":"1d92b1cf9660293664bcee3be22c40859603dece4502cedcf53e0b0301683d7e"},"package":"665fbc8384f961eb55c548daa2a4b1efff1f9d03b7a10f162ac6ad6a781ca966"}
|
||||
{"files":{".travis.yml":"91edce5ea2a1956399db4b17f580c8b7995af3aa9801c4314865f560c55d6d09","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"}
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
[package]
|
||||
name = "smallbitvec"
|
||||
version = "2.1.0"
|
||||
version = "2.1.1"
|
||||
authors = ["Matt Brubeck <mbrubeck@limpet.net>"]
|
||||
description = "A bit vector optimized for size and inline storage"
|
||||
documentation = "https://docs.rs/smallbitvec"
|
||||
|
|
|
@ -14,6 +14,19 @@
|
|||
//! inline capacity, it will allocate a buffer on the heap.
|
||||
//!
|
||||
//! [`SmallBitVec`]: struct.SmallBitVec.html
|
||||
//!
|
||||
//! # Example
|
||||
//!
|
||||
//! ```
|
||||
//! use smallbitvec::SmallBitVec;
|
||||
//!
|
||||
//! let mut v = SmallBitVec::new();
|
||||
//! v.push(true);
|
||||
//! v.push(false);
|
||||
//!
|
||||
//! assert_eq!(v[0], true);
|
||||
//! assert_eq!(v[1], false);
|
||||
//! ```
|
||||
|
||||
use std::cmp::max;
|
||||
use std::fmt;
|
||||
|
@ -77,6 +90,7 @@ pub struct SmallBitVec {
|
|||
}
|
||||
|
||||
/// Total number of bits per word.
|
||||
#[inline(always)]
|
||||
fn inline_bits() -> usize {
|
||||
size_of::<usize>() * 8
|
||||
}
|
||||
|
@ -85,11 +99,13 @@ fn inline_bits() -> usize {
|
|||
///
|
||||
/// - The rightmost bit is set to zero to signal an inline vector.
|
||||
/// - The position of the rightmost nonzero bit encodes the length.
|
||||
#[inline(always)]
|
||||
fn inline_capacity() -> usize {
|
||||
inline_bits() - 2
|
||||
}
|
||||
|
||||
/// Left shift amount to access the nth bit
|
||||
#[inline(always)]
|
||||
fn inline_shift(n: usize) -> usize {
|
||||
debug_assert!(n <= inline_capacity());
|
||||
// The storage starts at the leftmost bit.
|
||||
|
@ -97,11 +113,13 @@ fn inline_shift(n: usize) -> usize {
|
|||
}
|
||||
|
||||
/// An inline vector with the nth bit set.
|
||||
#[inline(always)]
|
||||
fn inline_index(n: usize) -> usize {
|
||||
1 << inline_shift(n)
|
||||
}
|
||||
|
||||
/// An inline vector with the leftmost `n` bits set.
|
||||
#[inline(always)]
|
||||
fn inline_ones(n: usize) -> usize {
|
||||
if n == 0 {
|
||||
0
|
||||
|
@ -157,11 +175,13 @@ impl Header {
|
|||
}
|
||||
|
||||
/// The number of `Storage` elements to allocate to hold a header.
|
||||
#[inline(always)]
|
||||
fn header_len() -> usize {
|
||||
size_of::<Header>() / size_of::<Storage>()
|
||||
}
|
||||
|
||||
/// The minimum number of `Storage` elements to hold at least `cap` bits.
|
||||
#[inline(always)]
|
||||
fn buffer_len(cap: usize) -> usize {
|
||||
(cap + bits_per_storage() - 1) / bits_per_storage()
|
||||
}
|
||||
|
@ -176,6 +196,7 @@ impl SmallBitVec {
|
|||
}
|
||||
|
||||
/// Create a vector containing `len` bits, each set to `val`.
|
||||
#[inline]
|
||||
pub fn from_elem(len: usize, val: bool) -> SmallBitVec {
|
||||
if len <= inline_capacity() {
|
||||
return SmallBitVec {
|
||||
|
@ -194,6 +215,7 @@ impl SmallBitVec {
|
|||
|
||||
/// Create an empty vector with enough storage pre-allocated to store at least `cap` bits
|
||||
/// without resizing.
|
||||
#[inline]
|
||||
pub fn with_capacity(cap: usize) -> SmallBitVec {
|
||||
// Use inline storage if possible.
|
||||
if cap <= inline_capacity() {
|
||||
|
@ -246,6 +268,7 @@ impl SmallBitVec {
|
|||
}
|
||||
|
||||
/// Get the nth bit in this bit vector, without bounds checks.
|
||||
#[inline]
|
||||
pub unsafe fn get_unchecked(&self, n: usize) -> bool {
|
||||
if self.is_inline() {
|
||||
self.data & inline_index(n) != 0
|
||||
|
@ -258,6 +281,7 @@ impl SmallBitVec {
|
|||
}
|
||||
|
||||
/// Set the nth bit in this bit vector to `val`. Panics if the index is out of bounds.
|
||||
#[inline]
|
||||
pub fn set(&mut self, n: usize, val: bool) {
|
||||
assert!(n < self.len(), "Index {} out of bounds", n);
|
||||
unsafe {
|
||||
|
@ -266,6 +290,7 @@ impl SmallBitVec {
|
|||
}
|
||||
|
||||
/// Set the nth bit in this bit vector to `val`, without bounds checks.
|
||||
#[inline]
|
||||
pub unsafe fn set_unchecked(&mut self, n: usize, val: bool) {
|
||||
if self.is_inline() {
|
||||
if val {
|
||||
|
@ -318,6 +343,7 @@ impl SmallBitVec {
|
|||
/// assert_eq!(v.len(), 0);
|
||||
/// assert_eq!(v.pop(), None);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn pop(&mut self) -> Option<bool> {
|
||||
let old_len = self.len();
|
||||
if old_len == 0 {
|
||||
|
@ -333,6 +359,7 @@ impl SmallBitVec {
|
|||
/// Remove and return the bit at index `idx`, shifting all later bits toward the front.
|
||||
///
|
||||
/// Panics if the index is out of bounds.
|
||||
#[inline]
|
||||
pub fn remove(&mut self, idx: usize) -> bool {
|
||||
let len = self.len();
|
||||
let val = self[idx];
|
||||
|
@ -373,6 +400,7 @@ impl SmallBitVec {
|
|||
}
|
||||
|
||||
/// Remove all elements from the vector, without deallocating its buffer.
|
||||
#[inline]
|
||||
pub fn clear(&mut self) {
|
||||
unsafe {
|
||||
self.set_len(0);
|
||||
|
@ -386,6 +414,7 @@ impl SmallBitVec {
|
|||
/// Panics if the new capacity overflows `usize`.
|
||||
///
|
||||
/// Re-allocates only if `self.capacity() < self.len() + additional`.
|
||||
#[inline]
|
||||
pub fn reserve(&mut self, additional: usize) {
|
||||
let old_cap = self.capacity();
|
||||
let new_cap = self.len()
|
||||
|
@ -403,6 +432,7 @@ impl SmallBitVec {
|
|||
///
|
||||
/// If this makes the vector longer, then the values of its new elements
|
||||
/// are not specified.
|
||||
#[inline]
|
||||
unsafe fn set_len(&mut self, len: usize) {
|
||||
debug_assert!(len <= self.capacity());
|
||||
if self.is_inline() {
|
||||
|
@ -416,6 +446,7 @@ impl SmallBitVec {
|
|||
}
|
||||
|
||||
/// Returns an iterator that yields the bits of the vector in order, as `bool` values.
|
||||
#[inline]
|
||||
pub fn iter(&self) -> Iter {
|
||||
Iter {
|
||||
vec: self,
|
||||
|
@ -430,12 +461,14 @@ impl SmallBitVec {
|
|||
/// let r = v.range(1..3);
|
||||
/// assert_eq!(r[1], true);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn range(&self, range: Range<usize>) -> VecRange {
|
||||
assert!(range.end <= self.len(), "range out of bounds");
|
||||
VecRange { vec: &self, range }
|
||||
}
|
||||
|
||||
/// Returns true if all the bits in the vec are set to zero/false.
|
||||
#[inline]
|
||||
pub fn all_false(&self) -> bool {
|
||||
let mut len = self.len();
|
||||
if len == 0 {
|
||||
|
@ -465,6 +498,7 @@ impl SmallBitVec {
|
|||
}
|
||||
|
||||
/// Returns true if all the bits in the vec are set to one/true.
|
||||
#[inline]
|
||||
pub fn all_true(&self) -> bool {
|
||||
let mut len = self.len();
|
||||
if len == 0 {
|
||||
|
@ -532,6 +566,7 @@ 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.
|
||||
#[inline]
|
||||
pub fn heap_ptr(&self) -> Option<*const usize> {
|
||||
if self.is_heap() {
|
||||
Some((self.data & !HEAP_FLAG) as *const Storage)
|
||||
|
@ -541,30 +576,36 @@ impl SmallBitVec {
|
|||
}
|
||||
|
||||
/// If the rightmost bit is set, then we treat it as inline storage.
|
||||
#[inline]
|
||||
fn is_inline(&self) -> bool {
|
||||
self.data & HEAP_FLAG == 0
|
||||
}
|
||||
|
||||
/// Otherwise, `data` is a pointer to a heap allocation.
|
||||
#[inline]
|
||||
fn is_heap(&self) -> bool {
|
||||
!self.is_inline()
|
||||
}
|
||||
|
||||
/// Get the header of a heap-allocated vector.
|
||||
#[inline]
|
||||
fn header_raw(&self) -> *mut Header {
|
||||
assert!(self.is_heap());
|
||||
(self.data & !HEAP_FLAG) as *mut Header
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn header_mut(&mut self) -> &mut Header {
|
||||
unsafe { &mut *self.header_raw() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn header(&self) -> &Header {
|
||||
unsafe { &*self.header_raw() }
|
||||
}
|
||||
|
||||
/// Get the buffer of a heap-allocated vector.
|
||||
#[inline]
|
||||
fn buffer_raw(&self) -> *mut [Storage] {
|
||||
unsafe {
|
||||
let header_ptr = self.header_raw();
|
||||
|
@ -575,10 +616,12 @@ impl SmallBitVec {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn buffer_mut(&mut self) -> &mut [Storage] {
|
||||
unsafe { &mut *self.buffer_raw() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn buffer(&self) -> &[Storage] {
|
||||
unsafe { &*self.buffer_raw() }
|
||||
}
|
||||
|
@ -677,7 +720,7 @@ impl Clone for SmallBitVec {
|
|||
impl Index<usize> for SmallBitVec {
|
||||
type Output = bool;
|
||||
|
||||
#[inline]
|
||||
#[inline(always)]
|
||||
fn index(&self, i: usize) -> &bool {
|
||||
assert!(i < self.len(), "index out of range");
|
||||
if self.get(i).unwrap() {
|
||||
|
@ -831,6 +874,7 @@ pub struct VecRange<'a> {
|
|||
}
|
||||
|
||||
impl<'a> VecRange<'a> {
|
||||
#[inline]
|
||||
pub fn iter(&self) -> Iter<'a> {
|
||||
Iter {
|
||||
vec: self.vec,
|
||||
|
|
Загрузка…
Ссылка в новой задаче