Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: servo/rust-smallvec
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.13.1
Choose a base ref
...
head repository: servo/rust-smallvec
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2
Choose a head ref
Loading
Showing with 1,930 additions and 1,853 deletions.
  1. +25 −20 .github/workflows/main.yml
  2. +2 −1 .gitignore
  3. +6 −8 Cargo.toml
  4. +16 −1 README.md
  5. +30 −11 benches/bench.rs
  6. +0 −192 fuzz/Cargo.lock
  7. +1 −1 fuzz/Cargo.toml
  8. +9 −15 fuzz/fuzz_targets/smallvec_ops.rs
  9. +1 −1 fuzz/travis-fuzz.sh
  10. +0 −1 scripts/run_miri.sh
  11. +0 −19 src/arbitrary.rs
  12. +1,517 −1,444 src/lib.rs
  13. +0 −19 src/specialization.rs
  14. +322 −119 src/tests.rs
  15. +1 −1 tests/macro.rs
45 changes: 25 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [auto]
branches: [v2]
pull_request:
workflow_dispatch:

@@ -12,26 +12,23 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
toolchain: ["stable", "beta", "nightly", "1.36.0"]
toolchain: ["stable", "beta", "nightly", "1.57.0"]
include:
- toolchain: stable
env:
DO_FUZZ: 1
fuzz: 1
- toolchain: beta
env:
DO_FUZZ: 1
fuzz: 1
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install packages
run: sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc libiberty-dev
- 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
@@ -46,10 +43,6 @@ jobs:
if: matrix.toolchain == 'nightly'
run: cargo check --verbose --no-default-features

- name: Cargo test w/ union
if: matrix.toolchain == 'beta'
run: cargo test --verbose --features union

- name: Cargo test all features
if: matrix.toolchain == 'nightly'
run: cargo test --verbose --all-features
@@ -61,19 +54,31 @@ jobs:
- name: miri
if: matrix.toolchain == 'nightly'
run: bash ./scripts/run_miri.sh
env:
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

no-std:
name: no_std
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
target: thumbv7m-none-eabi
- name: Cargo build
run: cargo build --verbose

build_result:
name: homu build finished
runs-on: ubuntu-latest
needs:
- "linux-ci"
- "no-std"

steps:
- name: Mark the job as successful
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
/Cargo.lock
Cargo.lock
/fuzz/hfuzz_target
/.vscode
14 changes: 6 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "smallvec"
version = "1.9.0"
edition = "2018"
version = "2.0.0-alpha.10"
edition = "2021"
rust-version = "1.57"
authors = ["The Servo Project Developers"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/servo/rust-smallvec"
@@ -12,18 +13,15 @@ readme = "README.md"
documentation = "https://docs.rs/smallvec/"

[features]
const_generics = []
const_new = ["const_generics"]
write = []
union = []
std = []
specialization = []
may_dangle = []
extract_if = []

[dependencies]
serde = { version = "1", optional = true, default-features = false }
arbitrary = { version = "1", optional = true }

[dev_dependencies]
[dev-dependencies]
bincode = "1.0.1"

[package.metadata.docs.rs]
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
rust-smallvec
=============

> **⚠️ Note:**
> This is the code for smallvec 2.0, which is not yet ready for release. For
> details about the changes in version 2.0, please see [#183], [#240], and [#284].
>
> The source code for the latest smallvec 1.x.y release can be found on the
> [v1 branch]. Bug fixes for smallvec 1 should be based on that branch, while
> new feature development should go on the v2 branch.
[v1 branch]: https://github.com/servo/rust-smallvec/tree/v1
[#183]: https://github.com/servo/rust-smallvec/issues/183
[#240]: https://github.com/servo/rust-smallvec/issues/240
[#284]: https://github.com/servo/rust-smallvec/issues/284

## About smallvec

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

[Release notes](https://github.com/servo/rust-smallvec/releases)
@@ -13,7 +28,7 @@ rust-smallvec
use smallvec::{SmallVec, smallvec};

// This SmallVec can hold up to 4 items on the stack:
let mut v: SmallVec<[i32; 4]> = smallvec![1, 2, 3, 4];
let mut v: SmallVec<i32, 4> = smallvec![1, 2, 3, 4];

// It will automatically move its contents to the heap if
// contains more than four items:
41 changes: 30 additions & 11 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#![feature(test)]
#![allow(deprecated)]

#[macro_use]
extern crate smallvec;
extern crate test;

use self::test::Bencher;
use smallvec::{ExtendFromSlice, SmallVec};
use smallvec::{smallvec, SmallVec};
use test::Bencher;

const VEC_SIZE: usize = 16;
const SPILLED_SIZE: usize = 100;

trait Vector<T>: for<'a> From<&'a [T]> + Extend<T> + ExtendFromSlice<T> {
trait Vector<T>: for<'a> From<&'a [T]> + Extend<T> {
fn new() -> Self;
fn push(&mut self, val: T);
fn pop(&mut self) -> Option<T>;
fn remove(&mut self, p: usize) -> T;
fn insert(&mut self, n: usize, val: T);
fn from_elem(val: T, n: usize) -> Self;
fn from_elems(val: &[T]) -> Self;
fn extend_from_slice(&mut self, other: &[T]);
}

impl<T: Copy> Vector<T> for Vec<T> {
@@ -49,9 +48,13 @@ impl<T: Copy> Vector<T> for Vec<T> {
fn from_elems(val: &[T]) -> Self {
val.to_owned()
}

fn extend_from_slice(&mut self, other: &[T]) {
Vec::extend_from_slice(self, other)
}
}

impl<T: Copy> Vector<T> for SmallVec<[T; VEC_SIZE]> {
impl<T: Copy> Vector<T> for SmallVec<T, VEC_SIZE> {
fn new() -> Self {
Self::new()
}
@@ -79,6 +82,10 @@ impl<T: Copy> Vector<T> for SmallVec<[T; VEC_SIZE]> {
fn from_elems(val: &[T]) -> Self {
SmallVec::from_slice(val)
}

fn extend_from_slice(&mut self, other: &[T]) {
SmallVec::extend_from_slice(self, other)
}
}

macro_rules! make_benches {
@@ -93,7 +100,7 @@ macro_rules! make_benches {
}

make_benches! {
SmallVec<[u64; VEC_SIZE]> {
SmallVec<u64, VEC_SIZE> {
bench_push => gen_push(SPILLED_SIZE as _),
bench_push_small => gen_push(VEC_SIZE as _),
bench_insert_push => gen_insert_push(SPILLED_SIZE as _),
@@ -104,6 +111,8 @@ make_benches! {
bench_remove_small => gen_remove(VEC_SIZE as _),
bench_extend => gen_extend(SPILLED_SIZE as _),
bench_extend_small => gen_extend(VEC_SIZE as _),
bench_extend_filtered => gen_extend_filtered(SPILLED_SIZE as _),
bench_extend_filtered_small => gen_extend_filtered(VEC_SIZE as _),
bench_from_iter => gen_from_iter(SPILLED_SIZE as _),
bench_from_iter_small => gen_from_iter(VEC_SIZE as _),
bench_from_slice => gen_from_slice(SPILLED_SIZE as _),
@@ -128,6 +137,8 @@ make_benches! {
bench_remove_vec_small => gen_remove(VEC_SIZE as _),
bench_extend_vec => gen_extend(SPILLED_SIZE as _),
bench_extend_vec_small => gen_extend(VEC_SIZE as _),
bench_extend_vec_filtered => gen_extend_filtered(SPILLED_SIZE as _),
bench_extend_vec_filtered_small => gen_extend_filtered(VEC_SIZE as _),
bench_from_iter_vec => gen_from_iter(SPILLED_SIZE as _),
bench_from_iter_vec_small => gen_from_iter(VEC_SIZE as _),
bench_from_slice_vec => gen_from_slice(SPILLED_SIZE as _),
@@ -211,6 +222,14 @@ fn gen_extend<V: Vector<u64>>(n: u64, b: &mut Bencher) {
});
}

fn gen_extend_filtered<V: Vector<u64>>(n: u64, b: &mut Bencher) {
b.iter(|| {
let mut vec = V::new();
vec.extend((0..n).filter(|i| i % 2 == 0));
vec
});
}

fn gen_from_iter<V: Vector<u64>>(n: u64, b: &mut Bencher) {
let v: Vec<u64> = (0..n).collect();
b.iter(|| {
@@ -263,15 +282,15 @@ fn gen_from_elem<V: Vector<u64>>(n: usize, b: &mut Bencher) {
fn bench_insert_many(b: &mut Bencher) {
#[inline(never)]
fn insert_many_noinline<I: IntoIterator<Item = u64>>(
vec: &mut SmallVec<[u64; VEC_SIZE]>,
vec: &mut SmallVec<u64, VEC_SIZE>,
index: usize,
iterable: I,
) {
vec.insert_many(index, iterable)
}

b.iter(|| {
let mut vec = SmallVec::<[u64; VEC_SIZE]>::new();
let mut vec = SmallVec::<u64, VEC_SIZE>::new();
insert_many_noinline(&mut vec, 0, 0..SPILLED_SIZE as _);
insert_many_noinline(&mut vec, 0, 0..SPILLED_SIZE as _);
vec
@@ -282,7 +301,7 @@ fn bench_insert_many(b: &mut Bencher) {
fn bench_insert_from_slice(b: &mut Bencher) {
let v: Vec<u64> = (0..SPILLED_SIZE as _).collect();
b.iter(|| {
let mut vec = SmallVec::<[u64; VEC_SIZE]>::new();
let mut vec = SmallVec::<u64, VEC_SIZE>::new();
vec.insert_from_slice(0, &v);
vec.insert_from_slice(0, &v);
vec
@@ -292,7 +311,7 @@ fn bench_insert_from_slice(b: &mut Bencher) {
#[bench]
fn bench_macro_from_list(b: &mut Bencher) {
b.iter(|| {
let vec: SmallVec<[u64; 16]> = smallvec![
let vec: SmallVec<u64, 16> = smallvec![
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 36, 0x40, 0x80,
0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, 0x10000, 0x20000, 0x40000,
0x80000, 0x100000,
Loading