Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New modifications #155

Closed
wants to merge 24 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not use the no_std feature
c410-f3r committed Jun 16, 2019

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
commit c109e5c02ac8f64843d368c083dcb8b43e3b8bca
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -18,12 +18,10 @@ serde = { version = "1", optional = true }
bincode = "1.0.1"

[features]
alloc = []
const_generics = []
default = ["alloc"]
may_dangle = []
specialization = []
std = ["alloc"]
std = []
union = []

[lib]
14 changes: 8 additions & 6 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#![feature(test)]

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

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

const VEC_SIZE: usize = 16;
const SPILLED_SIZE: usize = 100;
@@ -273,7 +271,11 @@ 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![
#[cfg(feature = "const_generics")]
let vec: SmallVec<u64, 16>;
#[cfg(not(feature = "const_generics"))]
let vec: SmallVec<[u64; 16]>;
vec = 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,
@@ -292,4 +294,4 @@ fn bench_macro_from_list_vec(b: &mut Bencher) {
];
vec
});
}
}
83 changes: 34 additions & 49 deletions lib.rs
Original file line number Diff line number Diff line change
@@ -31,15 +31,8 @@
#![cfg_attr(feature = "may_dangle", feature(dropck_eyepatch))]
#![cfg_attr(feature = "specialization", feature(specialization))]
#![cfg_attr(feature = "union", feature(untagged_unions))]
#![cfg_attr(not(feature = "alloc"), no_std)]
#![deny(missing_docs)]

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "serde")]
extern crate serde;

use core::{
borrow::{Borrow, BorrowMut},
cmp,
@@ -1543,23 +1536,15 @@ impl_array!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32

#[cfg(test)]
mod tests {
use crate::SmallVec;
extern crate alloc;

use crate::SmallVec;
use alloc::{
rc::Rc,
boxed::Box,
};
use core::iter::FromIterator;

#[cfg(feature = "std")]
use std::borrow::ToOwned;
#[cfg(not(feature = "std"))]
use alloc::borrow::ToOwned;
#[cfg(feature = "std")]
use std::rc::Rc;
#[cfg(not(feature = "std"))]
use alloc::rc::Rc;
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[test]
pub fn test_zero() {
let mut v = SmallVec::<[_; 0]>::new();
@@ -1574,51 +1559,51 @@ mod tests {
#[test]
pub fn test_inline() {
let mut v = SmallVec::<[_; 16]>::new();
v.push("hello".to_owned());
v.push("there".to_owned());
v.push("hello");
v.push("there");
assert_eq!(&*v, &[
"hello".to_owned(),
"there".to_owned(),
"hello",
"there",
][..]);
}

#[test]
pub fn test_spill() {
let mut v = SmallVec::<[_; 2]>::new();
v.push("hello".to_owned());
v.push("hello");
assert_eq!(v[0], "hello");
v.push("there".to_owned());
v.push("burma".to_owned());
v.push("there");
v.push("burma");
assert_eq!(v[0], "hello");
v.push("shave".to_owned());
v.push("shave");
assert_eq!(&*v, &[
"hello".to_owned(),
"there".to_owned(),
"burma".to_owned(),
"shave".to_owned(),
"hello",
"there",
"burma",
"shave",
][..]);
}

#[test]
pub fn test_double_spill() {
let mut v = SmallVec::<[_; 2]>::new();
v.push("hello".to_owned());
v.push("there".to_owned());
v.push("burma".to_owned());
v.push("shave".to_owned());
v.push("hello".to_owned());
v.push("there".to_owned());
v.push("burma".to_owned());
v.push("shave".to_owned());
v.push("hello");
v.push("there");
v.push("burma");
v.push("shave");
v.push("hello");
v.push("there");
v.push("burma");
v.push("shave");
assert_eq!(&*v, &[
"hello".to_owned(),
"there".to_owned(),
"burma".to_owned(),
"shave".to_owned(),
"hello".to_owned(),
"there".to_owned(),
"burma".to_owned(),
"shave".to_owned(),
"hello",
"there",
"burma",
"shave",
"hello",
"there",
"burma",
"shave",
][..]);
}

1 change: 0 additions & 1 deletion scripts/test-common.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
STABLE_FEATURES=(
alloc
serde
std
)