aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2021-08-09 10:47:58 -0700
committerJoel Galenson <jgalenson@google.com>2021-08-09 10:47:58 -0700
commit874ba7dc380c50540af907bcbe65182c9d331707 (patch)
tree7c9207d77f9ab146b60fdb9130e559073803c92f
parent2a7eb705096ad92acfe89fdd2d487f7b4be2a098 (diff)
downloadtinyvec-android-s-beta-5.tar.gz
Upgrade rust/crates/tinyvec to 1.3.1android-s-beta-5android-s-beta-5
Test: make Change-Id: I1a901c023db9f9c52760e89d3cd1b2ab903821d0
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--CHANGELOG.md9
-rw-r--r--Cargo.toml6
-rw-r--r--Cargo.toml.orig4
-rw-r--r--METADATA8
-rw-r--r--rustfmt.toml4
-rw-r--r--src/arrayvec.rs54
-rw-r--r--src/tinyvec.rs57
-rw-r--r--tests/arrayvec.rs3
9 files changed, 134 insertions, 13 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index d6de403..a951fcc 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
{
"git": {
- "sha1": "b6313725a26509d574ccf72885bc9c85fc4f476b"
+ "sha1": "a4bbfa9864d6a9d5ac607841025b517e618f3c8f"
}
}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8cc2ad7..ea5226b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,14 @@
# Changelog
+## 1.3.1
+
+* Improved the performance of the `clone_from` method [pr 144](https://github.com/Lokathor/tinyvec/pull/144)
+
+## 1.3.0
+
+* [jeffa5](https://github.com/jeffa5) added arbitrary implementations for `TinyVec` and `ArrayVec` [pr 146](https://github.com/Lokathor/tinyvec/pull/146).
+* [elomatreb](https://github.com/elomatreb) implemented `DoubleEndedIterator` for `TinyVecIterator` [pr 145](https://github.com/Lokathor/tinyvec/pull/145).
+
## 1.2.0
* [Cryptjar](https://github.com/Cryptjar) removed the `A:Array` bound on the struct of `ArrayVec<A:Array>`,
diff --git a/Cargo.toml b/Cargo.toml
index 905979a..fec505e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "tinyvec"
-version = "1.2.0"
+version = "1.3.1"
authors = ["Lokathor <zefria@gmail.com>"]
description = "`tinyvec` provides 100% safe vec-like data structures."
keywords = ["vec", "no_std", "no-std"]
@@ -37,6 +37,10 @@ required-features = ["alloc"]
name = "macros"
harness = false
required-features = ["alloc"]
+[dependencies.arbitrary]
+version = "1"
+optional = true
+
[dependencies.serde]
version = "1.0"
optional = true
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 2652d09..d0b0e31 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,7 +1,7 @@
[package]
name = "tinyvec"
description = "`tinyvec` provides 100% safe vec-like data structures."
-version = "1.2.0"
+version = "1.3.1"
authors = ["Lokathor <zefria@gmail.com>"]
edition = "2018"
license = "Zlib OR Apache-2.0 OR MIT"
@@ -13,6 +13,8 @@ repository = "https://github.com/Lokathor/tinyvec"
tinyvec_macros = { version = "0.1", optional = true }
# Provides `Serialize` and `Deserialize` implementations
serde = { version = "1.0", optional = true, default-features = false }
+# Provides derived `Arbitrary` implementations
+arbitrary = { version = "1", optional = true }
[features]
default = []
diff --git a/METADATA b/METADATA
index e240ffb..b1c756c 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/tinyvec/tinyvec-1.2.0.crate"
+ value: "https://static.crates.io/crates/tinyvec/tinyvec-1.3.1.crate"
}
- version: "1.2.0"
+ version: "1.3.1"
license_type: NOTICE
last_upgrade_date {
year: 2021
- month: 5
- day: 19
+ month: 8
+ day: 9
}
}
diff --git a/rustfmt.toml b/rustfmt.toml
index 23b0fd5..59b3aae 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,5 +1,3 @@
-# Based on
-# https://github.com/rust-lang/rustfmt/blob/rustfmt-1.4.19/Configurations.md
# Stable
edition = "2018"
@@ -12,5 +10,5 @@ use_small_heuristics = "Max"
# Unstable
format_code_in_doc_comments = true
-merge_imports = true
wrap_comments = true
+imports_granularity="Crate"
diff --git a/src/arrayvec.rs b/src/arrayvec.rs
index ba351c1..7cf1bfc 100644
--- a/src/arrayvec.rs
+++ b/src/arrayvec.rs
@@ -101,12 +101,48 @@ macro_rules! array_vec {
/// assert_eq!(no_ints.len(), 0);
/// ```
#[repr(C)]
-#[derive(Clone, Copy)]
pub struct ArrayVec<A> {
len: u16,
pub(crate) data: A,
}
+impl<A> Clone for ArrayVec<A>
+where
+ A: Array + Clone,
+ A::Item: Clone,
+{
+ #[inline]
+ fn clone(&self) -> Self {
+ Self { data: self.data.clone(), len: self.len }
+ }
+
+ #[inline]
+ fn clone_from(&mut self, o: &Self) {
+ let iter = self
+ .data
+ .as_slice_mut()
+ .iter_mut()
+ .zip(o.data.as_slice())
+ .take(self.len.max(o.len) as usize);
+ for (dst, src) in iter {
+ dst.clone_from(src)
+ }
+ if let Some(to_drop) =
+ self.data.as_slice_mut().get_mut((o.len as usize)..(self.len as usize))
+ {
+ to_drop.iter_mut().for_each(|x| drop(take(x)));
+ }
+ self.len = o.len;
+ }
+}
+
+impl<A> Copy for ArrayVec<A>
+where
+ A: Array + Copy,
+ A::Item: Copy,
+{
+}
+
impl<A: Array> Default for ArrayVec<A> {
fn default() -> Self {
Self { len: 0, data: A::default() }
@@ -180,6 +216,22 @@ where
}
}
+#[cfg(all(feature = "arbitrary", feature = "nightly_const_generics"))]
+#[cfg_attr(
+ docs_rs,
+ doc(cfg(all(feature = "arbitrary", feature = "nightly_const_generics")))
+)]
+impl<'a, T, const N: usize> arbitrary::Arbitrary<'a> for ArrayVec<[T; N]>
+where
+ T: arbitrary::Arbitrary<'a> + Default,
+{
+ fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
+ let v = <[T; N]>::arbitrary(u)?;
+ let av = ArrayVec::from(v);
+ Ok(av)
+ }
+}
+
impl<A: Array> ArrayVec<A> {
/// Move all values from `other` into this vec.
///
diff --git a/src/tinyvec.rs b/src/tinyvec.rs
index 8b058a4..3e884fc 100644
--- a/src/tinyvec.rs
+++ b/src/tinyvec.rs
@@ -91,7 +91,6 @@ pub enum TinyVecConstructor<A: Array> {
/// let empty_tv = tiny_vec!([u8; 16]);
/// let some_ints = tiny_vec!([i32; 4] => 1, 2, 3);
/// ```
-#[derive(Clone)]
#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))]
pub enum TinyVec<A: Array> {
#[allow(missing_docs)]
@@ -100,6 +99,34 @@ pub enum TinyVec<A: Array> {
Heap(Vec<A::Item>),
}
+impl<A> Clone for TinyVec<A>
+where
+ A: Array + Clone,
+ A::Item: Clone,
+{
+ #[inline]
+ fn clone(&self) -> Self {
+ match self {
+ Self::Heap(v) => Self::Heap(v.clone()),
+ Self::Inline(v) => Self::Inline(v.clone()),
+ }
+ }
+
+ #[inline]
+ fn clone_from(&mut self, o: &Self) {
+ if o.len() > self.len() {
+ self.reserve(o.len() - self.len());
+ } else {
+ self.truncate(o.len());
+ }
+ let (start, end) = o.split_at(self.len());
+ for (dst, src) in self.iter_mut().zip(start) {
+ dst.clone_from(src);
+ }
+ self.extend_from_slice(end);
+ }
+}
+
impl<A: Array> Default for TinyVec<A> {
#[inline]
#[must_use]
@@ -178,6 +205,21 @@ where
}
}
+#[cfg(feature = "arbitrary")]
+#[cfg_attr(docs_rs, doc(cfg(feature = "arbitrary")))]
+impl<'a, A> arbitrary::Arbitrary<'a> for TinyVec<A>
+where
+ A: Array,
+ A::Item: arbitrary::Arbitrary<'a>,
+{
+ fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
+ let v = Vec::arbitrary(u)?;
+ let mut tv = TinyVec::Heap(v);
+ tv.shrink_to_fit();
+ Ok(tv)
+ }
+}
+
impl<A: Array> TinyVec<A> {
/// Returns whether elements are on heap
#[inline(always)]
@@ -1190,6 +1232,19 @@ impl<A: Array> Iterator for TinyVecIterator<A> {
}
}
+impl<A: Array> DoubleEndedIterator for TinyVecIterator<A> {
+ impl_mirrored! {
+ type Mirror = TinyVecIterator;
+
+ #[inline]
+ fn next_back(self: &mut Self) -> Option<Self::Item>;
+
+ #[cfg(feature = "rustc_1_40")]
+ #[inline]
+ fn nth_back(self: &mut Self, n: usize) -> Option<Self::Item>;
+ }
+}
+
impl<A: Array> Debug for TinyVecIterator<A>
where
A::Item: Debug,
diff --git a/tests/arrayvec.rs b/tests/arrayvec.rs
index 15c5b64..e400317 100644
--- a/tests/arrayvec.rs
+++ b/tests/arrayvec.rs
@@ -460,7 +460,8 @@ fn ArrayVec_try_from_slice() {
assert!(fits.is_ok());
assert_eq!(fits.unwrap().as_slice(), &[1, 2]);
- let doesnt_fit: Result<ArrayVec<[i32; 2]>, _> = ArrayVec::try_from(&nums[..4]);
+ let doesnt_fit: Result<ArrayVec<[i32; 2]>, _> =
+ ArrayVec::try_from(&nums[..4]);
assert!(doesnt_fit.is_err());
}