summaryrefslogtreecommitdiffstats
path: root/vendor/zerovec/src/flexzerovec
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/zerovec/src/flexzerovec
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/zerovec/src/flexzerovec')
-rw-r--r--vendor/zerovec/src/flexzerovec/databake.rs41
-rw-r--r--vendor/zerovec/src/flexzerovec/owned.rs29
-rw-r--r--vendor/zerovec/src/flexzerovec/slice.rs12
-rw-r--r--vendor/zerovec/src/flexzerovec/vec.rs2
4 files changed, 43 insertions, 41 deletions
diff --git a/vendor/zerovec/src/flexzerovec/databake.rs b/vendor/zerovec/src/flexzerovec/databake.rs
index 23bf156ef..4ce5f7dea 100644
--- a/vendor/zerovec/src/flexzerovec/databake.rs
+++ b/vendor/zerovec/src/flexzerovec/databake.rs
@@ -8,16 +8,24 @@ use databake::*;
impl Bake for FlexZeroVec<'_> {
fn bake(&self, env: &CrateEnv) -> TokenStream {
env.insert("zerovec");
- let bytes = self.as_bytes();
- quote! { unsafe { ::zerovec::vecs::FlexZeroSlice::from_byte_slice_unchecked(&[#(#bytes),*]).as_flexzerovec() } }
+ if self.is_empty() {
+ quote! { ::zerovec::vecs::FlexZeroVec::new() }
+ } else {
+ let slice = self.as_ref().bake(env);
+ quote! { #slice.as_flexzerovec() }
+ }
}
}
impl Bake for &FlexZeroSlice {
fn bake(&self, env: &CrateEnv) -> TokenStream {
env.insert("zerovec");
- let bytes = self.as_bytes();
- quote! { unsafe { ::zerovec::vecs::FlexZeroSlice::from_byte_slice_unchecked(&[#(#bytes),*]) } }
+ if self.is_empty() {
+ quote! { ::zerovec::vecs::FlexZeroSlice::new_empty() }
+ } else {
+ let bytes = databake::Bake::bake(&self.as_bytes(), env);
+ quote! { unsafe { ::zerovec::vecs::FlexZeroSlice::from_byte_slice_unchecked(#bytes) } }
+ }
}
}
@@ -25,12 +33,16 @@ impl Bake for &FlexZeroSlice {
fn test_baked_vec() {
test_bake!(
FlexZeroVec,
+ const: crate::vecs::FlexZeroVec::new(),
+ zerovec
+ );
+ test_bake!(
+ FlexZeroVec,
const: unsafe {
- crate::vecs::FlexZeroSlice::from_byte_slice_unchecked(&[
- 2u8, 1u8, 0u8, 22u8, 0u8, 77u8, 1u8, 92u8, 17u8,
- ])
- .as_flexzerovec()
- },
+ crate::vecs::FlexZeroSlice::from_byte_slice_unchecked(
+ b"\x02\x01\0\x16\0M\x01\x11"
+ )
+ }.as_flexzerovec(),
zerovec
);
}
@@ -39,10 +51,15 @@ fn test_baked_vec() {
fn test_baked_slice() {
test_bake!(
&FlexZeroSlice,
+ const: crate::vecs::FlexZeroSlice::new_empty(),
+ zerovec
+ );
+ test_bake!(
+ &FlexZeroSlice,
const: unsafe {
- crate::vecs::FlexZeroSlice::from_byte_slice_unchecked(&[
- 2u8, 1u8, 0u8, 22u8, 0u8, 77u8, 1u8, 92u8, 17u8,
- ])
+ crate::vecs::FlexZeroSlice::from_byte_slice_unchecked(
+ b"\x02\x01\0\x16\0M\x01\x11"
+ )
},
zerovec
);
diff --git a/vendor/zerovec/src/flexzerovec/owned.rs b/vendor/zerovec/src/flexzerovec/owned.rs
index 1039c59ae..7d7bfb33d 100644
--- a/vendor/zerovec/src/flexzerovec/owned.rs
+++ b/vendor/zerovec/src/flexzerovec/owned.rs
@@ -30,7 +30,7 @@ impl FlexZeroVecOwned {
/// Obtains this [`FlexZeroVecOwned`] as a [`FlexZeroSlice`].
pub fn as_slice(&self) -> &FlexZeroSlice {
- let slice: &[u8] = &*self.0;
+ let slice: &[u8] = &self.0;
unsafe {
// safety: the slice is known to come from a valid parsed FlexZeroSlice
FlexZeroSlice::from_byte_slice_unchecked(slice)
@@ -39,7 +39,7 @@ impl FlexZeroVecOwned {
/// Mutably obtains this `FlexZeroVecOwned` as a [`FlexZeroSlice`].
pub(crate) fn as_mut_slice(&mut self) -> &mut FlexZeroSlice {
- let slice: &mut [u8] = &mut *self.0;
+ let slice: &mut [u8] = &mut self.0;
unsafe {
// safety: the slice is known to come from a valid parsed FlexZeroSlice
FlexZeroSlice::from_byte_slice_mut_unchecked(slice)
@@ -255,42 +255,27 @@ mod test {
use super::*;
fn check_contents(fzv: &FlexZeroSlice, expected: &[usize]) {
- assert_eq!(
- fzv.len(),
- expected.len(),
- "len: {:?} != {:?}",
- fzv,
- expected
- );
+ assert_eq!(fzv.len(), expected.len(), "len: {fzv:?} != {expected:?}");
assert_eq!(
fzv.is_empty(),
expected.is_empty(),
- "is_empty: {:?} != {:?}",
- fzv,
- expected
+ "is_empty: {fzv:?} != {expected:?}"
);
assert_eq!(
fzv.first(),
expected.first().copied(),
- "first: {:?} != {:?}",
- fzv,
- expected
+ "first: {fzv:?} != {expected:?}"
);
assert_eq!(
fzv.last(),
expected.last().copied(),
- "last: {:?} != {:?}",
- fzv,
- expected
+ "last: {fzv:?} != {expected:?}"
);
for i in 0..(expected.len() + 1) {
assert_eq!(
fzv.get(i),
expected.get(i).copied(),
- "@{}: {:?} != {:?}",
- i,
- fzv,
- expected
+ "@{i}: {fzv:?} != {expected:?}"
);
}
}
diff --git a/vendor/zerovec/src/flexzerovec/slice.rs b/vendor/zerovec/src/flexzerovec/slice.rs
index ee164d05b..fb58d6215 100644
--- a/vendor/zerovec/src/flexzerovec/slice.rs
+++ b/vendor/zerovec/src/flexzerovec/slice.rs
@@ -22,6 +22,12 @@ pub struct FlexZeroSlice {
data: [u8],
}
+impl fmt::Debug for FlexZeroSlice {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ self.to_vec().fmt(f)
+ }
+}
+
impl PartialEq for FlexZeroSlice {
fn eq(&self, other: &Self) -> bool {
self.width == other.width && self.data == other.data
@@ -507,12 +513,6 @@ impl FlexZeroSlice {
}
}
-impl fmt::Debug for &FlexZeroSlice {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{:?}", self.to_vec())
- }
-}
-
#[inline]
pub(crate) fn get_item_width(item_bytes: &[u8; USIZE_WIDTH]) -> usize {
USIZE_WIDTH - item_bytes.iter().rev().take_while(|b| **b == 0).count()
diff --git a/vendor/zerovec/src/flexzerovec/vec.rs b/vendor/zerovec/src/flexzerovec/vec.rs
index a08f54e5d..dfd64ce65 100644
--- a/vendor/zerovec/src/flexzerovec/vec.rs
+++ b/vendor/zerovec/src/flexzerovec/vec.rs
@@ -134,7 +134,7 @@ impl<'a> FlexZeroVec<'a> {
/// let zv: FlexZeroVec = FlexZeroVec::new();
/// assert!(zv.is_empty());
/// ```
- pub fn new() -> Self {
+ pub const fn new() -> Self {
Self::Borrowed(FlexZeroSlice::new_empty())
}