diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 758022c..f4ffdc7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,9 +2,11 @@ name: CI on: push: - branches: [auto] + branches: [v1] pull_request: workflow_dispatch: + merge_group: + types: [checks_requested] jobs: ci: @@ -15,11 +17,9 @@ jobs: os: [ubuntu-latest] include: - toolchain: stable - env: - DO_FUZZ: 1 + fuzz: 1 - toolchain: beta - env: - DO_FUZZ: 1 + fuzz: 1 - os: windows-latest toolchain: nightly @@ -28,16 +28,14 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Install packages - if: matrix.os == 'ubuntu-latest' + - name: Install packages for fuzzing + if: runner.os == 'Linux' && matrix.fuzz == 1 run: sudo apt-get update -y && sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc libiberty-dev - name: Install toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: ${{ matrix.toolchain }} - override: true - name: Cargo build run: cargo build --verbose @@ -81,12 +79,12 @@ jobs: MIRIFLAGS: '-Zmiri-tag-raw-pointers' - name: fuzz - if: env.DO_FUZZ == '1' + if: matrix.fuzz == 1 working-directory: fuzz - run: ./travis_fuzz.sh + run: ./travis-fuzz.sh build_result: - name: homu build finished + name: Result runs-on: ubuntu-latest needs: - "ci" diff --git a/Cargo.toml b/Cargo.toml index ea86e9f..5c6770c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "smallvec" -version = "1.11.0" +version = "1.11.1" edition = "2018" authors = ["The Servo Project Developers"] license = "MIT OR Apache-2.0" @@ -36,7 +36,7 @@ debugger_test_parser = "0.1.0" [package.metadata.docs.rs] all-features = true -rustdoc-args = ["--cfg", "docsrs"] +rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] [[test]] name = "debugger_visualizer" diff --git a/fuzz/travis-fuzz.sh b/fuzz/travis-fuzz.sh index 5782ea7..ff44d25 100755 --- a/fuzz/travis-fuzz.sh +++ b/fuzz/travis-fuzz.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -cargo install --force honggfuzz --version 0.5.47 +cargo install --force honggfuzz --version "^0.5.47" for TARGET in fuzz_targets/*; do FILENAME=$(basename $TARGET) FILE="${FILENAME%.*}" diff --git a/src/lib.rs b/src/lib.rs index fa3d8ca..8281fb1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1120,7 +1120,7 @@ impl SmallVec { unsafe { let (mut ptr, mut len, cap) = self.triple_mut(); if *len == cap { - self.reserve(1); + self.reserve_one_unchecked(); let (heap_ptr, heap_len) = self.data.heap_mut(); ptr = heap_ptr; len = heap_len; @@ -1225,13 +1225,23 @@ impl SmallVec { infallible(self.try_reserve(additional)) } + /// Internal method used to grow in push() and insert(), where we know already we have to grow. + #[cold] + fn reserve_one_unchecked(&mut self) { + debug_assert_eq!(self.len(), self.capacity()); + let new_cap = self.len() + .checked_add(1) + .and_then(usize::checked_next_power_of_two) + .expect("capacity overflow"); + infallible(self.try_grow(new_cap)) + } + /// Reserve capacity for `additional` more elements to be inserted. /// /// May reserve more space to avoid frequent reallocations. pub fn try_reserve(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { - // prefer triple_mut() even if triple() would work - // so that the optimizer removes duplicated calls to it - // from callers like insert() + // prefer triple_mut() even if triple() would work so that the optimizer removes duplicated + // calls to it from callers. let (_, &mut len, cap) = self.triple_mut(); if cap - len >= additional { return Ok(()); @@ -1357,10 +1367,14 @@ impl SmallVec { /// /// Panics if `index > len`. pub fn insert(&mut self, index: usize, element: A::Item) { - self.reserve(1); - unsafe { - let (ptr, len_ptr, _) = self.triple_mut(); + let (mut ptr, mut len_ptr, cap) = self.triple_mut(); + if *len_ptr == cap { + self.reserve_one_unchecked(); + let (heap_ptr, heap_len_ptr) = self.data.heap_mut(); + ptr = heap_ptr; + len_ptr = heap_len_ptr; + } let mut ptr = ptr.as_ptr(); let len = *len_ptr; ptr = ptr.add(index); @@ -1758,6 +1772,7 @@ where /// elements toward the back. /// /// For slices of `Copy` types, this is more efficient than `insert`. + #[inline] pub fn insert_from_slice(&mut self, index: usize, slice: &[A::Item]) { self.reserve(slice.len());