summaryrefslogtreecommitdiffstats
path: root/vendor/bstr/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/bstr/src
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/bstr/src')
-rw-r--r--vendor/bstr/src/ascii.rs6
-rw-r--r--vendor/bstr/src/byteset/scalar.rs6
-rw-r--r--vendor/bstr/src/escape_bytes.rs6
-rw-r--r--vendor/bstr/src/impls.rs86
4 files changed, 93 insertions, 11 deletions
diff --git a/vendor/bstr/src/ascii.rs b/vendor/bstr/src/ascii.rs
index 259d41fe7..5bbbdad82 100644
--- a/vendor/bstr/src/ascii.rs
+++ b/vendor/bstr/src/ascii.rs
@@ -1,5 +1,3 @@
-use core::mem;
-
// The following ~400 lines of code exists for exactly one purpose, which is
// to optimize this code:
//
@@ -24,7 +22,7 @@ use core::mem;
// _mm_movemask_epi8.
#[cfg(any(test, miri, not(target_arch = "x86_64")))]
-const USIZE_BYTES: usize = mem::size_of::<usize>();
+const USIZE_BYTES: usize = core::mem::size_of::<usize>();
#[cfg(any(test, miri, not(target_arch = "x86_64")))]
const FALLBACK_LOOP_SIZE: usize = 2 * USIZE_BYTES;
@@ -119,7 +117,7 @@ fn first_non_ascii_byte_fallback(slice: &[u8]) -> usize {
fn first_non_ascii_byte_sse2(slice: &[u8]) -> usize {
use core::arch::x86_64::*;
- const VECTOR_SIZE: usize = mem::size_of::<__m128i>();
+ const VECTOR_SIZE: usize = core::mem::size_of::<__m128i>();
const VECTOR_ALIGN: usize = VECTOR_SIZE - 1;
const VECTOR_LOOP_SIZE: usize = 4 * VECTOR_SIZE;
diff --git a/vendor/bstr/src/byteset/scalar.rs b/vendor/bstr/src/byteset/scalar.rs
index 28bff673d..46ebfba1e 100644
--- a/vendor/bstr/src/byteset/scalar.rs
+++ b/vendor/bstr/src/byteset/scalar.rs
@@ -4,11 +4,7 @@
use core::{cmp, usize};
-#[cfg(target_pointer_width = "32")]
-const USIZE_BYTES: usize = 4;
-
-#[cfg(target_pointer_width = "64")]
-const USIZE_BYTES: usize = 8;
+const USIZE_BYTES: usize = core::mem::size_of::<usize>();
// The number of bytes to loop at in one iteration of memchr/memrchr.
const LOOP_SIZE: usize = 2 * USIZE_BYTES;
diff --git a/vendor/bstr/src/escape_bytes.rs b/vendor/bstr/src/escape_bytes.rs
index 62c1fcdda..b6775055c 100644
--- a/vendor/bstr/src/escape_bytes.rs
+++ b/vendor/bstr/src/escape_bytes.rs
@@ -129,11 +129,13 @@ enum EscapeState {
/// expose this for core-only use cases too. I'm just not quite sure what the
/// API should be.
#[derive(Clone, Debug)]
+#[cfg(feature = "alloc")]
pub(crate) struct UnescapeBytes<I> {
it: I,
state: UnescapeState,
}
+#[cfg(feature = "alloc")]
impl<I: Iterator<Item = char>> UnescapeBytes<I> {
pub(crate) fn new<T: IntoIterator<IntoIter = I>>(
t: T,
@@ -142,6 +144,7 @@ impl<I: Iterator<Item = char>> UnescapeBytes<I> {
}
}
+#[cfg(feature = "alloc")]
impl<I: Iterator<Item = char>> Iterator for UnescapeBytes<I> {
type Item = u8;
@@ -265,6 +268,7 @@ impl<I: Iterator<Item = char>> Iterator for UnescapeBytes<I> {
/// The state used by the FSM in the unescaping iterator.
#[derive(Clone, Debug)]
+#[cfg(feature = "alloc")]
enum UnescapeState {
/// The start state. Look for an escape sequence, otherwise emit the next
/// codepoint as-is.
@@ -283,6 +287,7 @@ enum UnescapeState {
HexSecond(char),
}
+#[cfg(feature = "alloc")]
impl UnescapeState {
/// Create a new `Bytes` variant with the given slice.
///
@@ -337,6 +342,7 @@ impl UnescapeState {
/// # Panics
///
/// This panics if `ch` is not in `[0-9A-Fa-f]`.
+#[cfg(feature = "alloc")]
fn char_to_hexdigit(ch: char) -> u8 {
u8::try_from(ch.to_digit(16).unwrap()).unwrap()
}
diff --git a/vendor/bstr/src/impls.rs b/vendor/bstr/src/impls.rs
index e017cf1ac..861ca5376 100644
--- a/vendor/bstr/src/impls.rs
+++ b/vendor/bstr/src/impls.rs
@@ -66,7 +66,7 @@ mod bstring {
};
use alloc::{
- borrow::{Borrow, Cow, ToOwned},
+ borrow::{Borrow, BorrowMut, Cow, ToOwned},
string::String,
vec,
vec::Vec,
@@ -134,6 +134,13 @@ mod bstring {
}
}
+ impl Borrow<[u8]> for BString {
+ #[inline]
+ fn borrow(&self) -> &[u8] {
+ self.as_bytes()
+ }
+ }
+
impl Borrow<BStr> for BString {
#[inline]
fn borrow(&self) -> &BStr {
@@ -141,6 +148,41 @@ mod bstring {
}
}
+ impl Borrow<BStr> for Vec<u8> {
+ #[inline]
+ fn borrow(&self) -> &BStr {
+ self.as_slice().as_bstr()
+ }
+ }
+
+ impl Borrow<BStr> for String {
+ #[inline]
+ fn borrow(&self) -> &BStr {
+ self.as_bytes().as_bstr()
+ }
+ }
+
+ impl BorrowMut<[u8]> for BString {
+ #[inline]
+ fn borrow_mut(&mut self) -> &mut [u8] {
+ self.as_bytes_mut()
+ }
+ }
+
+ impl BorrowMut<BStr> for BString {
+ #[inline]
+ fn borrow_mut(&mut self) -> &mut BStr {
+ self.as_mut_bstr()
+ }
+ }
+
+ impl BorrowMut<BStr> for Vec<u8> {
+ #[inline]
+ fn borrow_mut(&mut self) -> &mut BStr {
+ BStr::new_mut(self.as_mut_slice())
+ }
+ }
+
impl ToOwned for BStr {
type Owned = BString;
@@ -338,7 +380,12 @@ mod bstring {
}
mod bstr {
- use core::{cmp::Ordering, convert::TryFrom, fmt, ops};
+ use core::{
+ borrow::{Borrow, BorrowMut},
+ cmp::Ordering,
+ convert::TryFrom,
+ fmt, ops,
+ };
#[cfg(feature = "alloc")]
use alloc::{borrow::Cow, boxed::Box, string::String, vec::Vec};
@@ -612,6 +659,41 @@ mod bstr {
}
}
+ impl Borrow<BStr> for [u8] {
+ #[inline]
+ fn borrow(&self) -> &BStr {
+ self.as_bstr()
+ }
+ }
+
+ impl Borrow<BStr> for str {
+ #[inline]
+ fn borrow(&self) -> &BStr {
+ self.as_bytes().as_bstr()
+ }
+ }
+
+ impl Borrow<[u8]> for BStr {
+ #[inline]
+ fn borrow(&self) -> &[u8] {
+ self.as_bytes()
+ }
+ }
+
+ impl BorrowMut<BStr> for [u8] {
+ #[inline]
+ fn borrow_mut(&mut self) -> &mut BStr {
+ BStr::new_mut(self)
+ }
+ }
+
+ impl BorrowMut<[u8]> for BStr {
+ #[inline]
+ fn borrow_mut(&mut self) -> &mut [u8] {
+ self.as_bytes_mut()
+ }
+ }
+
impl<'a> Default for &'a BStr {
fn default() -> &'a BStr {
BStr::from_bytes(b"")