commit_hash stringlengths 40 40 | author stringlengths 1 57 | date timestamp[s]date 2010-07-26 04:45:09 2026-04-14 18:21:10 | message stringlengths 8 1.39M | diff stringlengths 68 51.2k | files_changed int64 1 136 | insertions int64 0 2.35k | deletions int64 0 1.9k |
|---|---|---|---|---|---|---|---|
4a9678934753f1273ce8b7484994d2d9ecbf5351 | Amanieu d'Antras | 2016-05-23T11:02:32 | Bump version to 0.2.3 | diff --git a/Cargo.toml b/Cargo.toml
index 42a3aa2..b654436 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "parking_lot"
-version = "0.2.2"
+version = "0.2.3"
authors = ["Amanieu d'Antras <amanieu@gmail.com>"]
description = "Compact and efficient synchronization primitives. Also provides ... | 1 | 1 | 1 |
b7c8ab4abd1ac1a8b653a8b4429d93db55e98dfa | Amanieu d'Antras | 2016-05-23T10:51:02 | Move RwLock shared count overflow out of the inline fast path | diff --git a/src/raw_rwlock.rs b/src/raw_rwlock.rs
index b2dcd06..c9879e1 100644
--- a/src/raw_rwlock.rs
+++ b/src/raw_rwlock.rs
@@ -89,14 +89,10 @@ impl RawRwLock {
if self.state.elision_acquire(0, SHARED_COUNT_INC) {
return;
}
- } else {
+ } else if let Some(ne... | 1 | 2 | 6 |
ba133487aada8298deae4e4e0e89764d2fea96e0 | Amanieu d'Antras | 2016-05-23T10:31:15 | Bump version to 0.2.2 | diff --git a/Cargo.toml b/Cargo.toml
index e006d5d..42a3aa2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "parking_lot"
-version = "0.2.1"
+version = "0.2.2"
authors = ["Amanieu d'Antras <amanieu@gmail.com>"]
description = "Compact and efficient synchronization primitives. Also provides ... | 1 | 1 | 1 |
f4aab473791dc2d425032283a329f71f6a28dda5 | Amanieu d'Antras | 2016-05-23T05:35:43 | Bump version to 0.2.1 | diff --git a/Cargo.toml b/Cargo.toml
index a2c70b8..e006d5d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "parking_lot"
-version = "0.2.0"
+version = "0.2.1"
authors = ["Amanieu d'Antras <amanieu@gmail.com>"]
description = "Compact and efficient synchronization primitives. Also provides ... | 1 | 1 | 1 |
481f1c4a15ffcdea0c3b8cd1aa72329234e320ae | Amanieu d'Antras | 2016-05-17T22:35:27 | Add benchmarks to measure Mutex and RwLock performance | diff --git a/benchmark/Cargo.toml b/benchmark/Cargo.toml
new file mode 100644
index 0000000..1f8f63c
--- /dev/null
+++ b/benchmark/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "parking_lot-benchmark"
+version = "0.0.0"
+authors = ["Amanieu d'Antras <amanieu@gmail.com>"]
+
+[dependencies]
+parking_lot = {path = ".."}
... | 4 | 538 | 0 |
3e7d392dbf29f66e247bc5d6e519cf8f5697bb6b | Amanieu d'Antras | 2016-05-23T02:54:25 | Increase the spin limit | diff --git a/src/lib.rs b/src/lib.rs
index 5ba0aee..30fdf31 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -134,8 +134,8 @@ extern crate winapi;
#[cfg(windows)]
extern crate kernel32;
-// Spin limit from JikesRVM & Webkit experiments
-const SPIN_LIMIT: usize = 40;
+// Spin limit, determined experimentally
+const SPIN_... | 1 | 2 | 2 |
09e8553de7e2a7d322e3aad42e686c2a2a6facad | Amanieu d'Antras | 2016-05-23T01:24:31 | Add test to ensure lock guards can be sent to other threads | diff --git a/src/mutex.rs b/src/mutex.rs
index cd0aa0c..6ce4852 100644
--- a/src/mutex.rs
+++ b/src/mutex.rs
@@ -374,4 +374,12 @@ mod tests {
let comp: &[i32] = &[4, 2, 5];
assert_eq!(&*mutex.lock(), comp);
}
+
+ #[test]
+ fn test_mutexguard_send() {
+ fn send<T: Send>(_: T) {}
+
+ ... | 2 | 17 | 0 |
fb576941488365dbebe39905a9d038a63bff318d | Amanieu d'Antras | 2016-05-22T18:53:56 | New RwLock algorithm which should scale much better | diff --git a/src/raw_rwlock.rs b/src/raw_rwlock.rs
index bf73eb5..c73e900 100644
--- a/src/raw_rwlock.rs
+++ b/src/raw_rwlock.rs
@@ -147,9 +147,12 @@ impl RawRwLock {
continue;
}
- // If there are no parked exclusive threads, try spinning a few
- // times
- ... | 1 | 53 | 46 |
2631ea686d2a31d64b68826b22f71dce4d3dbec3 | Amanieu d'Antras | 2016-05-22T05:32:22 | Small code cleanups | diff --git a/src/mutex.rs b/src/mutex.rs
index 0cc6992..cd0aa0c 100644
--- a/src/mutex.rs
+++ b/src/mutex.rs
@@ -201,7 +201,7 @@ impl<'a, T: ?Sized + 'a> Drop for MutexGuard<'a, T> {
// Helper function used by Condvar, not publicly exported
#[inline]
pub fn guard_lock<'a, T: ?Sized>(guard: &MutexGuard<'a, T>) -> &'a... | 2 | 5 | 5 |
43abbc964e9cf296a852c22cd452405b82e76ee6 | Amanieu d'Antras | 2016-05-21T19:44:36 | Add Windows keyed event implementation of ThreadParker | diff --git a/Cargo.toml b/Cargo.toml
index 88a9cb9..a269c3b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,6 +15,10 @@ smallvec = "0.1"
[target.'cfg(target_os = "linux")'.dependencies]
libc = "0.2"
+[target.'cfg(windows)'.dependencies]
+winapi = "0.2"
+kernel32-sys = "0.2"
+
[dev-dependencies]
rand = "0.3"
lazy... | 5 | 321 | 83 |
cf64fd967b3c8fe9862af0ace8084cf2c46c0687 | Amanieu d'Antras | 2016-05-15T19:55:53 | Add Linux futex implementation of ThreadParker | diff --git a/Cargo.toml b/Cargo.toml
index 35e8ed9..88a9cb9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,9 @@ keywords = ["mutex", "condvar", "rwlock", "once", "thread"]
[dependencies]
smallvec = "0.1"
+[target.'cfg(target_os = "linux")'.dependencies]
+libc = "0.2"
+
[dev-dependencies]
rand = "0.3"
lazy... | 4 | 127 | 1 |
de76cf5208be37acef1a91d47241b96971a71d03 | Amanieu d'Antras | 2016-05-21T23:30:48 | Bump version to 0.1.3 | diff --git a/Cargo.toml b/Cargo.toml
index 5da0951..35e8ed9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "parking_lot"
-version = "0.1.2"
+version = "0.1.3"
authors = ["Amanieu d'Antras <amanieu@gmail.com>"]
description = "Compact and efficient synchronization primitives. Also provides ... | 1 | 1 | 1 |
cfb45d2bd43d206b52c403e608864b1c30d4ebec | Amanieu d'Antras | 2016-05-21T23:29:49 | Small bugfix and code cleanups | diff --git a/src/once.rs b/src/once.rs
index a7ea61c..bab5667 100644
--- a/src/once.rs
+++ b/src/once.rs
@@ -238,6 +238,7 @@ impl Once {
}
// Loop back and check if the done bit was set
+ state = self.0.load(Ordering::Relaxed);
}
struct PanicGuard<'a>(&'a Once)... | 2 | 12 | 7 |
181a092b9ff46f10c6b08b9402372b788e1c2a93 | Amanieu d'Antras | 2016-05-21T07:13:16 | Add note about possible deadlocks with recursive read locks | diff --git a/src/rwlock.rs b/src/rwlock.rs
index bac9273..12f714e 100644
--- a/src/rwlock.rs
+++ b/src/rwlock.rs
@@ -20,7 +20,8 @@ use raw_rwlock::RawRwLock;
/// This lock will always prioritize writers over readers to avoid writer
/// starvation. This means that readers trying to acquire the lock will block
/// eve... | 1 | 7 | 10 |
9e048c4c033c1339ccd826458a64815493df1a71 | Amanieu d'Antras | 2016-05-20T03:01:46 | Bump version to 0.1.2 | diff --git a/Cargo.toml b/Cargo.toml
index 26c2273..5da0951 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "parking_lot"
-version = "0.1.1"
+version = "0.1.2"
authors = ["Amanieu d'Antras <amanieu@gmail.com>"]
description = "Compact and efficient synchronization primitives. Also provides ... | 1 | 1 | 1 |
91fd2845893cae0cbf3ff40c8f50cad75fe2fb95 | Amanieu d'Antras | 2016-05-20T02:24:39 | Fix excessive slowdown when unparking with many threads | diff --git a/Cargo.toml b/Cargo.toml
index 4116392..26c2273 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,6 +9,9 @@ repository = "https://github.com/Amanieu/parking_lot"
readme = "README.md"
keywords = ["mutex", "condvar", "rwlock", "once", "thread"]
+[dependencies]
+smallvec = "0.1"
+
[dev-dependencies]
rand = ... | 5 | 39 | 16 |
9edecd7a3633fa8f6a8b7bd7bb3902dbc5fe994a | Amanieu d'Antras | 2016-05-20T01:55:43 | Add missing function attributes | diff --git a/src/condvar.rs b/src/condvar.rs
index f0414ad..93576ed 100644
--- a/src/condvar.rs
+++ b/src/condvar.rs
@@ -17,6 +17,7 @@ pub struct WaitTimeoutResult(bool);
impl WaitTimeoutResult {
/// Returns whether the wait was known to have timed out.
+ #[inline]
pub fn timed_out(&self) -> bool {
... | 5 | 32 | 1 |
9782cd0ff02e10731fa193bcf4589820d08c1ae6 | Amanieu d'Antras | 2016-05-17T15:04:31 | Bump version to 0.1.1 | diff --git a/Cargo.toml b/Cargo.toml
index 0656cb1..4116392 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "parking_lot"
-version = "0.1.0"
+version = "0.1.1"
authors = ["Amanieu d'Antras <amanieu@gmail.com>"]
description = "Compact and efficient synchronization primitives. Also provides ... | 1 | 1 | 1 |
859c80c66eadc2d9d872bf6d685d821fa33e96a2 | Amanieu d'Antras | 2016-05-16T17:56:24 | Use AtomicBool for Condvar now that it is 1 byte | diff --git a/src/condvar.rs b/src/condvar.rs
index 563a027..20f31d5 100644
--- a/src/condvar.rs
+++ b/src/condvar.rs
@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
-use std::sync::atomic::{AtomicU8, Or... | 1 | 9 | 9 |
af583762c7160ca2867c9305777735a0d76147c2 | Georg Brandl | 2016-05-17T06:44:57 | Minor doc fix
These now return options, so return `None` when unsuccessful. | diff --git a/src/rwlock.rs b/src/rwlock.rs
index 267e5d0..9540cf4 100644
--- a/src/rwlock.rs
+++ b/src/rwlock.rs
@@ -131,7 +131,7 @@ impl<T: ?Sized> RwLock<T> {
/// Attempts to acquire this rwlock with shared read access.
///
- /// If the access could not be granted at this time, then `Err` is returned.
... | 1 | 2 | 2 |
f0ebd3ab299c0f0c2c4e21d5b218a4f1552b3c03 | Andrew Gallant | 2026-02-10T12:41:20 | deps: bump criterion | diff --git a/bench/Cargo.toml b/bench/Cargo.toml
index de1760f..01b857a 100644
--- a/bench/Cargo.toml
+++ b/bench/Cargo.toml
@@ -18,7 +18,7 @@ harness = false
path = "src/bench.rs"
[dependencies]
-criterion = "0.3.4"
+criterion = "0.8.2"
bstr = { version = "1.0.0", path = ".." }
# For comparisons.
unicode-segmen... | 1 | 1 | 1 |
d4710de3791c25958bf4b472a6e65ea1387fa4f2 | Andrew Gallant | 2025-10-26T19:05:23 | doc: switch to `doc_cfg` from `doc_auto_cfg`
This feature was renamed. Hopefully it will be stabilized soon.
Fixes #217 | diff --git a/Cargo.toml b/Cargo.toml
index 09de91a..b72ca86 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -49,7 +49,7 @@ all-features = true
# Since this crate's feature setup is pretty complicated, it is worth opting
# into a nightly unstable option to show the features that need to be enabled
# for public API items.... | 3 | 7 | 7 |
7b418fae5667a240de4181819dc539f62f459b05 | Andrew Gallant | 2025-08-12T12:05:42 | lint: add elided lifetime that rustc doesn't like | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index 13843fc..5b9b9e5 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -528,7 +528,7 @@ pub trait ByteSlice: private::Sealed {
#[cfg(not(unix))]
#[inline]
- fn imp(bytes: &[u8]) -> Cow<OsStr> {
+ fn imp(bytes: &[u8]) -> Cow<'_, O... | 1 | 1 | 1 |
efb8ec4858b3685b531a9abe3b00f862b3c3fb26 | Lieselotte | 2025-04-08T16:36:35 | api: `impl Default for Box<BStr>`
PR #206 | diff --git a/src/impls.rs b/src/impls.rs
index f09bb9e..0ad78fb 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -765,6 +765,14 @@ mod bstr {
}
}
+ #[cfg(feature = "alloc")]
+ impl Default for Box<BStr> {
+ #[inline]
+ fn default() -> Self {
+ BStr::from_boxed_bytes(Box::de... | 1 | 8 | 0 |
1ade79723ba102a05f66e10755dae9bc85fce461 | Josh Triplett | 2025-01-02T19:12:28 | impl: fix `impl_partial_eq_cow` to apply `.as_bytes()` and `&**` to the correct arguments
`impl_partial_eq_cow`, in its second trail impl, had the arguments the
wrong way around, applying `&**` to the ByteStr argument and
`.as_bytes()` to the `Cow`.
Fix it to use the same structure as `impl_partial_eq`.
PR #20... | diff --git a/src/impls.rs b/src/impls.rs
index fade074..f09bb9e 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -52,8 +52,8 @@ macro_rules! impl_partial_eq_cow {
impl<'a> PartialEq<$lhs> for $rhs {
#[inline]
fn eq(&self, other: &$lhs) -> bool {
- let this: &[u8] = (&**o... | 1 | 2 | 2 |
732fc99f3844d88dc40f33d95a7bc8f3f6bd2e5b | Josh Triplett | 2025-01-02T14:03:25 | impl: fix formatting of control characters \x1a through \x1f in Debug impl
Due to an incorrect range, control characters \x1a through \x1f get
formatted as Unicode \u escapes rather than hex \x escapes.
This commit fixes the range, adds a test and switches over to std's
`escape_ascii` to do more of the formatting... | diff --git a/src/impls.rs b/src/impls.rs
index 1b792dc..fade074 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -525,6 +525,9 @@ mod bstr {
for (s, e, ch) in self.char_indices() {
match ch {
'\0' => write!(f, "\\0")?,
+ '\x01'..='\x7f' => {
+ ... | 1 | 9 | 12 |
7cd46948f7c62ce4272b3df3341bb06fdeb20c5b | Josh Triplett | 2025-01-02T13:34:25 | impl: remove unused 'b lifetime from trait implementation macros
The macros implementing PartialEq and PartialOrd all provide lifetimes
'a and 'b to the types they receive, but none of the invocations of
these macros ever use 'b.
This was maybe a copy-and-paste gaffe?
PR #202 | diff --git a/src/impls.rs b/src/impls.rs
index 1c9614d..1b792dc 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -1,6 +1,6 @@
macro_rules! impl_partial_eq {
($lhs:ty, $rhs:ty) => {
- impl<'a, 'b> PartialEq<$rhs> for $lhs {
+ impl<'a> PartialEq<$rhs> for $lhs {
#[inline]
fn e... | 1 | 10 | 10 |
979b3435b4a9732f40e47c71cded1307a3d4f376 | Andrew Gallant | 2024-12-11T17:32:35 | cargo: exclude Unicode data files
This will mean that you can't easily run tests on the artifact uploaded
to crates.io, but I'm not sure that's a use case we really care about.
If this change breaks you, please file a new issue about it and your use
case: https://github.com/BurntSushi/bstr/issues
Fixes #200 | diff --git a/Cargo.toml b/Cargo.toml
index 9f3732b..43a699c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,7 +10,7 @@ readme = "README.md"
keywords = ["string", "str", "byte", "bytes", "text"]
license = "MIT OR Apache-2.0"
categories = ["text-processing", "encoding"]
-exclude = ["/.github", "/scripts"]
+exclude = [... | 1 | 1 | 1 |
71e468c19641edd869a44dc0632c9181e30bdb16 | Lukasz Anforowicz | 2024-10-25T16:42:49 | safety: introduce `ALIGN_MASK` based on `core::mem::align_of`
Fixes #194, Closes #197 | diff --git a/src/ascii.rs b/src/ascii.rs
index 464da96..7ef6b5c 100644
--- a/src/ascii.rs
+++ b/src/ascii.rs
@@ -24,6 +24,8 @@
#[cfg(any(test, miri, not(target_arch = "x86_64")))]
const USIZE_BYTES: usize = core::mem::size_of::<usize>();
#[cfg(any(test, miri, not(target_arch = "x86_64")))]
+const ALIGN_MASK: usize =... | 2 | 6 | 6 |
77e5fd762a0066364f6a322f97157d5c77d3781d | Josh Triplett | 2024-10-07T21:23:59 | lint: fix elided_named_lifetimes warning on nightly
A build on nightly currently produces this:
warning: elided lifetime has a name
--> src/escape_bytes.rs:15:43
|
14 | impl<'a> EscapeBytes<'a> {
| -- lifetime `'a` declared here
15 | pub(crate) fn new(bytes: &'a [u8]) -> EscapeBytes {
| ... | diff --git a/src/escape_bytes.rs b/src/escape_bytes.rs
index fb8c41d..d9fdf91 100644
--- a/src/escape_bytes.rs
+++ b/src/escape_bytes.rs
@@ -12,7 +12,7 @@ pub struct EscapeBytes<'a> {
}
impl<'a> EscapeBytes<'a> {
- pub(crate) fn new(bytes: &'a [u8]) -> EscapeBytes {
+ pub(crate) fn new(bytes: &'a [u8]) -> Esc... | 1 | 1 | 1 |
6b713be9c1ad7073425d72b4213d3d7c480ce8a7 | Josh Triplett | 2024-10-07T00:17:15 | impl: add PartialEq and PartialOrd instances for byte arrays `[u8; N]`
Add instances for `[u8; N]` and `&[u8; N]`, for convenience.
Closes #191 | diff --git a/src/impls.rs b/src/impls.rs
index ca20722..1c9614d 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -18,6 +18,26 @@ macro_rules! impl_partial_eq {
};
}
+macro_rules! impl_partial_eq_n {
+ ($lhs:ty, $rhs:ty) => {
+ impl<'a, 'b, const N: usize> PartialEq<$rhs> for $lhs {
+ #[inlin... | 1 | 68 | 0 |
af99a6ecb4723d0ea03982797a1becd8437d3f7d | Petr Beneš | 2024-07-28T11:42:38 | impl: fix discrepancy in upper/lower case in `impl fmt::Debug for BStr`
Make all of the debug output in lower-case.
Closes #188, Closes #189 | diff --git a/src/impls.rs b/src/impls.rs
index 4abc8b5..ca20722 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -487,7 +487,7 @@ mod bstr {
write!(f, "{}", ch.escape_debug())?;
} else {
for &b in self[s..e].as_bytes() {
- ... | 1 | 11 | 3 |
955fa1609eefb23fa3d324db1e57781f33b8fe3c | Ryan Lopopolo | 2023-05-22T00:45:05 | lint: `clippy::cast_lossless` and `clippy::unreadable_literal` lints | diff --git a/src/utf8.rs b/src/utf8.rs
index f096e39..054740c 100644
--- a/src/utf8.rs
+++ b/src/utf8.rs
@@ -813,10 +813,11 @@ pub fn decode_last_lossy<B: AsRef<[u8]>>(slice: B) -> (char, usize) {
#[inline]
pub fn decode_step(state: &mut usize, cp: &mut u32, b: u8) {
let class = CLASSES[b as usize];
+ let b =... | 1 | 3 | 2 |
65018f6ac6dc351a18b21931ba95ea82c4584499 | Ryan Lopopolo | 2023-05-22T00:35:59 | lint: `clippy::redundant_closure_for_method_calls` lint violation | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index 4b6753c..13843fc 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -3374,7 +3374,7 @@ pub struct Fields<'a> {
#[cfg(feature = "unicode")]
impl<'a> Fields<'a> {
fn new(bytes: &'a [u8]) -> Fields<'a> {
- Fields { it: bytes.fields_with(|ch| ch.is_w... | 1 | 1 | 1 |
dee0d9a486ac38a9c4e8b45fb0b2311379d00c86 | Ryan Lopopolo | 2023-05-22T00:33:56 | lint: `clippy::cloned_instead_of_copied` lint violation | diff --git a/src/ext_vec.rs b/src/ext_vec.rs
index 7868d7a..c83d9da 100644
--- a/src/ext_vec.rs
+++ b/src/ext_vec.rs
@@ -958,7 +958,7 @@ pub trait ByteVec: private::Sealed {
R: ops::RangeBounds<usize>,
B: AsRef<[u8]>,
{
- self.as_vec_mut().splice(range, replace_with.as_ref().iter().cloned(... | 1 | 1 | 1 |
c7f3d56dd064295a09187771acf8fe1082cfda12 | Ryan Lopopolo | 2023-05-22T00:32:55 | lint: `clippy::range_plus_one` lint violations | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index c81ba54..4b6753c 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -3744,7 +3744,7 @@ impl<'a> Iterator for LinesWithTerminator<'a> {
Some(line)
}
Some(end) => {
- let line = &self.bytes[..end + 1];
+ ... | 1 | 2 | 2 |
ef95d8848804b365e477edee53b643d7d503db0e | Ryan Lopopolo | 2023-05-22T00:31:41 | lint: `clippy::transmute_ptr_to_ptr` lint violations
This is a pedantic lint, but it removes a transmute where a cast will do.
The code is safe for the same reasons the transmute is safe: `BStr` is a repr
transparent wrapper around `[u8]`. | diff --git a/src/bstr.rs b/src/bstr.rs
index bf9b01e..de3aa3b 100644
--- a/src/bstr.rs
+++ b/src/bstr.rs
@@ -1,5 +1,3 @@
-use core::mem;
-
#[cfg(feature = "alloc")]
use alloc::boxed::Box;
@@ -72,12 +70,12 @@ impl BStr {
#[inline]
pub(crate) fn from_bytes(slice: &[u8]) -> &BStr {
- unsafe { mem::t... | 1 | 2 | 4 |
46afa00fb356ca53725cf853b77f0f4bb946a5a9 | Ryan Lopopolo | 2023-05-22T00:25:50 | style: use ptr.sub instead of ptr.offset with cast and assert | diff --git a/src/ascii.rs b/src/ascii.rs
index fbaf373..464da96 100644
--- a/src/ascii.rs
+++ b/src/ascii.rs
@@ -238,8 +238,7 @@ unsafe fn ptr_add(ptr: *const u8, amt: usize) -> *const u8 {
/// Decrement the given pointer by the given amount.
unsafe fn ptr_sub(ptr: *const u8, amt: usize) -> *const u8 {
- debug_a... | 1 | 1 | 2 |
d5a832d4d26cfcd44ded07216777684523329c7d | Ryan Lopopolo | 2023-05-21T17:20:21 | lint: `clippy::wildcard_in_or_patterns` lint violations | diff --git a/src/impls.rs b/src/impls.rs
index f5b8f38..4abc8b5 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -499,7 +499,10 @@ mod bstr {
| '\x7f' => {
write!(f, "\\x{:02x}", ch as u32)?;
}
- '\n' | '\r' | '\t' | _ => {
+ ... | 1 | 4 | 1 |
69e83813d817f68f3e4005a879c6c1de41492b6d | Ryan Lopopolo | 2023-05-21T17:14:21 | lint: `clippy::derived_hash_with_manual_eq` lint violations | diff --git a/src/bstr.rs b/src/bstr.rs
index ab3a232..bf9b01e 100644
--- a/src/bstr.rs
+++ b/src/bstr.rs
@@ -29,7 +29,6 @@ use alloc::boxed::Box;
/// The `Display` implementation behaves as if `BStr` were first lossily
/// converted to a `str`. Invalid UTF-8 bytes are substituted with the Unicode
/// replacement cod... | 3 | 17 | 4 |
d7c0038ebc5c4cc565bb20524a6cc23c6eb86d0a | Ryan Lopopolo | 2023-05-21T17:10:09 | lint: `clippy::ptr_offset_with_cast` lint violations | diff --git a/src/ascii.rs b/src/ascii.rs
index 5bbbdad..fbaf373 100644
--- a/src/ascii.rs
+++ b/src/ascii.rs
@@ -233,8 +233,7 @@ fn first_non_ascii_byte_mask(mask: usize) -> usize {
/// Increment the given pointer by the given amount.
unsafe fn ptr_add(ptr: *const u8, amt: usize) -> *const u8 {
- debug_assert!(a... | 1 | 1 | 2 |
36b000934d1f78f639b1939ade744d148073942f | Ryan Lopopolo | 2023-05-21T17:08:20 | lint: `clippy::needless_return` lint violations | diff --git a/src/byteset/mod.rs b/src/byteset/mod.rs
index 797f2a0..369ebac 100644
--- a/src/byteset/mod.rs
+++ b/src/byteset/mod.rs
@@ -14,7 +14,7 @@ fn build_table(byteset: &[u8]) -> [u8; 256] {
#[inline]
pub(crate) fn find(haystack: &[u8], byteset: &[u8]) -> Option<usize> {
match byteset.len() {
- 0 =>... | 1 | 4 | 4 |
2f2e04daa15d74675cf664db2974df65b2e8555a | Ryan Lopopolo | 2023-05-21T17:06:54 | lint: `clippy::while_let_on_iterator` lint violations | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index 87fe091..c81ba54 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -3428,7 +3428,7 @@ impl<'a, F: FnMut(char) -> bool> Iterator for FieldsWith<'a, F> {
}
}
}
- while let Some((_, e, ch)) = self.chars.next() {
+ ... | 2 | 3 | 3 |
7d426f94c1e34028b441606c2b1dc56d8abb667a | Ryan Lopopolo | 2023-05-21T17:03:04 | lint: `clippy::redundant_static_lifetimes` lint violations | diff --git a/src/unicode/grapheme.rs b/src/unicode/grapheme.rs
index 466448e..ca1d35d 100644
--- a/src/unicode/grapheme.rs
+++ b/src/unicode/grapheme.rs
@@ -219,7 +219,7 @@ pub fn decode_grapheme(bs: &[u8]) -> (&str, usize) {
let grapheme = unsafe { bs[..hm.offset()].to_str_unchecked() };
(grapheme, g... | 4 | 8 | 10 |
79ab089a78de450906d837b11b35e0cef7290f3d | Ryan Lopopolo | 2023-05-21T16:59:27 | lint: `ByteSlice::last_byte` | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index b7a8492..87fe091 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -3045,7 +3045,7 @@ pub trait ByteSlice: private::Sealed {
#[inline]
fn last_byte(&self) -> Option<u8> {
let bytes = self.as_bytes();
- bytes.get(bytes.len().saturatin... | 1 | 1 | 1 |
41be9a0823c7b8f0c82a8067b33dd738b83787f6 | Ryan Lopopolo | 2023-05-21T16:58:57 | lint: `clippy::map_clone` lint violations | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index 6c44cfa..b7a8492 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -3045,7 +3045,7 @@ pub trait ByteSlice: private::Sealed {
#[inline]
fn last_byte(&self) -> Option<u8> {
let bytes = self.as_bytes();
- bytes.get(bytes.len().saturatin... | 1 | 3 | 3 |
8db216fe53db7cf4989e5397b736470fd54abe44 | Ryan Lopopolo | 2023-05-21T16:57:37 | lint: `clippy::useless_conversion` lint violations | diff --git a/src/ext_vec.rs b/src/ext_vec.rs
index 1e6b55a..7868d7a 100644
--- a/src/ext_vec.rs
+++ b/src/ext_vec.rs
@@ -185,7 +185,7 @@ pub trait ByteVec: private::Sealed {
fn imp(os_str: OsString) -> Result<Vec<u8>, OsString> {
use std::os::unix::ffi::OsStringExt;
- Ok(Vec::from(os_... | 1 | 1 | 1 |
d2b24097e2669e8d5977c9f9224a1c06c06dd3a8 | Ryan Lopopolo | 2023-05-21T16:56:51 | lint: `clippy::needless_lifetimes` lint violations | diff --git a/src/bstr.rs b/src/bstr.rs
index 5036f06..ab3a232 100644
--- a/src/bstr.rs
+++ b/src/bstr.rs
@@ -60,7 +60,7 @@ impl BStr {
/// assert_eq!(a, c);
/// ```
#[inline]
- pub fn new<'a, B: ?Sized + AsRef<[u8]>>(bytes: &'a B) -> &'a BStr {
+ pub fn new<B: ?Sized + AsRef<[u8]>>(bytes: &B) -> &B... | 3 | 6 | 6 |
3a4676acf66b6c40faad0f0f003c9d982c193e99 | Ryan Lopopolo | 2023-05-21T16:55:19 | lint: `clippy::op_ref` lint violations | diff --git a/src/impls.rs b/src/impls.rs
index 17241e2..dcfa508 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -356,7 +356,7 @@ mod bstring {
impl PartialEq for BString {
#[inline]
fn eq(&self, other: &BString) -> bool {
- &self[..] == &other[..]
+ self[..] == other[..]
... | 1 | 1 | 1 |
430a33a2b9c1d371f11a224426d81927ec18ed03 | Ryan Lopopolo | 2023-05-21T16:53:52 | lint: `clippy::needless_borrow` lint violations | diff --git a/src/io.rs b/src/io.rs
index 43d9e1b..cab8b5a 100644
--- a/src/io.rs
+++ b/src/io.rs
@@ -142,7 +142,7 @@ pub trait BufReadExt: io::BufRead {
F: FnMut(&[u8]) -> io::Result<bool>,
{
self.for_byte_line_with_terminator(|line| {
- for_each_line(&trim_line_slice(&line))
+ ... | 1 | 4 | 4 |
d7c0ea44e83ef3c5f2bfc1238f12624bada970ba | Ryan Lopopolo | 2023-05-21T16:52:24 | lint: `clippy::get_first` lint violations | diff --git a/src/utf8.rs b/src/utf8.rs
index 5315f6b..b049f90 100644
--- a/src/utf8.rs
+++ b/src/utf8.rs
@@ -605,7 +605,7 @@ pub fn validate(slice: &[u8]) -> Result<(), Utf8Error> {
#[inline]
pub fn decode<B: AsRef<[u8]>>(slice: B) -> (Option<char>, usize) {
let slice = slice.as_ref();
- match slice.get(0) {
... | 1 | 1 | 1 |
907e90280fd0fe40680aea5a1bbbd0982c33b09e | Ryan Lopopolo | 2023-05-21T16:51:51 | lint: `clippy::deprecated_cfg_attr` lint violations | diff --git a/src/utf8.rs b/src/utf8.rs
index 910e9a5..5315f6b 100644
--- a/src/utf8.rs
+++ b/src/utf8.rs
@@ -37,7 +37,7 @@ const REJECT: usize = 0;
/// SAFETY: The decode below function relies on the correctness of these
/// equivalence classes.
-#[cfg_attr(rustfmt, rustfmt::skip)]
+#[rustfmt::skip]
const CLASSES:... | 1 | 2 | 2 |
06b1f14ccb43d67285ba7661a412b2fb9a2a711a | Petr Beneš | 2024-07-25T13:20:50 | api: add `impl<'a> From<&'a BString> for Cow<'a, BStr>`
This commit simplifies code in situations like:
```
let mut v = Vec::<Cow<'a, BStr>>::new();
let s = BString::new(...);
// Before this commit, we would have to do:
// v.push(s.as_bstr().into());
v.push(s.into());
```
PR #187 | diff --git a/src/impls.rs b/src/impls.rs
index b6c68d0..17241e2 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -268,6 +268,13 @@ mod bstring {
}
}
+ impl<'a> From<&'a BString> for Cow<'a, BStr> {
+ #[inline]
+ fn from(s: &'a BString) -> Cow<'a, BStr> {
+ Cow::Borrowed(s.as_b... | 1 | 7 | 0 |
8c4693531cf35049f06b80603444042546426155 | Andrew Gallant | 2024-02-24T18:55:43 | style: rejigger imports
Rust nightly grew some new lints about unnecessary imports. While I
could fix those, it would be better to just do `#![no_std]`
unconditionally, and then opt in as needed. This does mean we don't
really benefit from the `std` prelude, but this makes things a bit more
consistent and easier to gr... | diff --git a/src/byteset/mod.rs b/src/byteset/mod.rs
index c6c697c..797f2a0 100644
--- a/src/byteset/mod.rs
+++ b/src/byteset/mod.rs
@@ -82,6 +82,8 @@ pub(crate) fn rfind_not(haystack: &[u8], byteset: &[u8]) -> Option<usize> {
#[cfg(all(test, feature = "std", not(miri)))]
mod tests {
+ use alloc::vec::Vec;
+
... | 12 | 41 | 17 |
7b6e0259850dfbcfa4707e88e3a6a4f2a1ad4b34 | Andrew Gallant | 2024-02-24T18:42:51 | io: read of zero bytes should quit instantly
If a `read` gets zero bytes, then that's EOF and we should just quit.
Previously, we tried another `read_until`, but that was unintentional.
While our existing implementation was technically correct, this can have
undesirable user facing effects.
Fixes #180 | diff --git a/src/io.rs b/src/io.rs
index a648145..d6a1924 100644
--- a/src/io.rs
+++ b/src/io.rs
@@ -302,6 +302,9 @@ pub trait BufReadExt: io::BufRead {
// Lend out complete record slices from our buffer
{
let mut buf = self.fill_buf()?;
+ if buf.is_empty() {
+ ... | 1 | 3 | 0 |
cc13102d64de7b43efaf804046065b68f6c9a0c0 | Andrew Gallant | 2024-02-22T14:10:01 | bench: fix broken benchmark
I'm not sure how this ever worked? Apparently, a mutable ref to `corpus`
was being taken and thus emptied out after the first use. We fix it by
re-assigning for each run.
Ref #179 | diff --git a/bench/src/bench.rs b/bench/src/bench.rs
index 3f25438..b6687f4 100644
--- a/bench/src/bench.rs
+++ b/bench/src/bench.rs
@@ -244,9 +244,10 @@ fn sentences(c: &mut Criterion) {
fn byte_lines(c: &mut Criterion) {
use bstr::io::BufReadExt;
- let mut corpus = SUBTITLE_EN_HUGE;
+ let corpus = SUBTI... | 1 | 2 | 1 |
02e5a7c6515d084da39a171ad545acdb64b1df0a | Adrian Delgado | 2023-11-26T21:29:34 | api: impl Clone for Split, Find and several other iterators
Fixes #173, Closes #174 | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index 503e0b2..bf6942d 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -3246,7 +3246,7 @@ impl<'a> FinderReverse<'a> {
///
/// `'h` is the lifetime of the haystack while `'n` is the lifetime of the
/// needle.
-#[derive(Debug)]
+#[derive(Clone, Debug)]
pub st... | 1 | 8 | 8 |
35321c96d6ac37ec499162fbb2bb61bbd3788055 | Andrew Gallant | 2023-12-28T22:00:39 | deps: bump to memchr 2.7.0
This brings in a Clone impl for memchr::memmem::FindIter. | diff --git a/Cargo.toml b/Cargo.toml
index a9d681f..88fd516 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,7 +29,7 @@ unicode = ["dep:regex-automata"]
serde = ["dep:serde"]
[dependencies]
-memchr = { version = "2.6.1", default-features = false }
+memchr = { version = "2.7.1", default-features = false }
serde = { ... | 1 | 1 | 1 |
d03a8fdb50e2f6960b6045c29c3174565e212fef | Filip Andersson | 2023-11-09T17:22:08 | impl: add FromStr for BString
This seems fine to add since String also impls FromStr.
PR #170 | diff --git a/src/impls.rs b/src/impls.rs
index 861ca53..02ec0f2 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -63,6 +63,7 @@ macro_rules! impl_partial_ord {
mod bstring {
use core::{
cmp::Ordering, convert::TryFrom, fmt, iter::FromIterator, ops,
+ str::FromStr,
};
use alloc::{
@@ -90... | 1 | 16 | 0 |
09cfd76c91711507362628c482805eed32d5f6c0 | Andrew Gallant | 2023-10-09T22:18:07 | deps: bump to regex-automata 0.4.1
This brings in a bug fix that was causing all DFA deserialization to
fail: https://github.com/rust-lang/regex/commit/a2a1986b13aebbafc54ef4b7d9a76626270a0a24 | diff --git a/Cargo.toml b/Cargo.toml
index 60f90c3..d54ee12 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,7 +33,7 @@ memchr = { version = "2.6.1", default-features = false }
serde = { version = "1.0.85", default-features = false, optional = true }
[dependencies.regex-automata]
-version = "0.4.0"
+version = "0.4.1... | 1 | 1 | 1 |
c42ae78e160588f0a64235e5b4500a66143eab37 | Andrew Gallant | 2023-10-09T22:06:56 | deps: bump to regex-automata 0.4 | diff --git a/Cargo.toml b/Cargo.toml
index bde73c6..e46c129 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,7 +33,7 @@ memchr = { version = "2.6.1", default-features = false }
serde = { version = "1.0.85", default-features = false, optional = true }
[dependencies.regex-automata]
-version = "0.3.0"
+version = "0.4.0... | 1 | 1 | 1 |
880de74a99641295e2437b552170404665857696 | Jake Shadle | 2023-08-30T12:36:03 | cargo: exclude `scripts` directory
PR #167 | diff --git a/Cargo.toml b/Cargo.toml
index 0a268c4..a15a7fe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,7 +10,7 @@ readme = "README.md"
keywords = ["string", "str", "byte", "bytes", "text"]
license = "MIT OR Apache-2.0"
categories = ["text-processing", "encoding"]
-exclude = ["/.github"]
+exclude = ["/.github", ... | 1 | 1 | 1 |
bf2a2c18aa024f72b32235e7921aaf4da8a5eb9d | Andrew Gallant | 2023-08-29T14:18:00 | deps: upgrade to memchr 2.6
We can now utilize its `alloc` feature. And in particular, make the
`Finder::into_owned` API available only when `alloc` is enabled. We
don't need `std` for it, but did previously because `memchr` didn't
expose an `alloc` feature. | diff --git a/Cargo.toml b/Cargo.toml
index c4a7e5c..b4f5a49 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,12 +24,12 @@ bench = false
[features]
default = ["std", "unicode"]
std = ["alloc", "memchr/std", "serde?/std"]
-alloc = ["serde?/alloc"]
+alloc = ["memchr/alloc", "serde?/alloc"]
unicode = ["dep:regex-automat... | 2 | 6 | 6 |
f639abd59752e8c7954c9adcd8b03300bddc2453 | Ryan Lopopolo | 2023-05-21T02:51:03 | api: add more `Borrow` and `BorrowMut` trait impls
These additions allow `BStr`s and `BString`s to be used as lookup keys
in `HashMap`s containing byte slices, byte vecs, and strings.
I mirrored these impls off of the ones in `std`.
There is some concern that these impls aren't appropriate for one reason
or another.... | diff --git a/src/impls.rs b/src/impls.rs
index e017cf1..861ca53 100644
--- a/src/impls.rs
+++ b/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,
... | 1 | 84 | 2 |
7c369ae734966fdd146f223c92daa1899601864b | Andrew Gallant | 2023-05-21T11:43:25 | imp: this removes the only target pointer width specific code
... by replacing it with `core::mem::size_of::<usize>()`.
This is generally a better way to go. It was motivated by folks filing
issues about 16-bit support not working. It's not clear whether this
alone will make 16-bit work, but perhaps it's a step towar... | diff --git a/src/ascii.rs b/src/ascii.rs
index 259d41f..5bbbdad 100644
--- a/src/ascii.rs
+++ b/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... | 2 | 3 | 9 |
853d803664596cd5b4ece2f2c35cf1a144be7d95 | Andrew Gallant | 2023-03-18T01:36:46 | api: add ByteSlice::escape_bytes and ByteVec::unescape_bytes
I grew weary of re-implementing basically these exact routines all of
the time. In my work, it comes up surprisingly often that I want to be
able to accept any kind of input---including arbitrary bytes---but
either don't want to force the user to figure out ... | diff --git a/src/escape_bytes.rs b/src/escape_bytes.rs
new file mode 100644
index 0000000..62c1fcd
--- /dev/null
+++ b/src/escape_bytes.rs
@@ -0,0 +1,445 @@
+/// An iterator of `char` values that represent an escaping of arbitrary bytes.
+///
+/// The lifetime parameter `'a` refers to the lifetime of the bytes being
+/... | 4 | 590 | 0 |
1d5a9354d46164f4406c78fe28d7f33acbfced75 | Andrew Gallant | 2023-03-18T01:36:23 | api: impl From<[u8; N]> for BString and BStr
This makes things like 'BString::from(b"foo")' work. Yay!
For 'BStr', we can only add an impl for &[u8; N]. But that means
'BStr::from(b"foo")' should work too. | diff --git a/src/impls.rs b/src/impls.rs
index c063cb6..e017cf1 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -156,6 +156,20 @@ mod bstring {
}
}
+ impl<'a, const N: usize> From<&'a [u8; N]> for BString {
+ #[inline]
+ fn from(s: &'a [u8; N]) -> BString {
+ BString::from(&s... | 1 | 21 | 0 |
e2296b7293ba1381c800141cb7921b9629a42414 | Michael Henry | 2023-02-20T12:41:20 | api: impl AsRef<BStr> for BStr
This allow functions that accept `AsRef<BStr>` to also accept `BStr`
itself, e.g.:
fn quoted<B: AsRef<BStr>>(s: B) -> String {
let s = s.as_ref();
if s.is_ascii() && !s.contains(&b'\'') {
format!("'{}'", s)
} else {
format!("{:... | diff --git a/src/impls.rs b/src/impls.rs
index 7ae4510..c063cb6 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -563,6 +563,13 @@ mod bstr {
}
}
+ impl AsRef<BStr> for BStr {
+ #[inline]
+ fn as_ref(&self) -> &BStr {
+ self
+ }
+ }
+
impl AsRef<BStr> for [u8] {... | 1 | 7 | 0 |
dc12f949f1a438a3dd2e93897e8be16b54c966ba | Christofer Nolander | 2023-02-01T16:53:59 | api: impl Clone for Box<BStr>
The blanket Clone impl for Box<T> requires
that T is Sized, but of course, BStr is not sized.
So we provide our own impl.
PR #145 | diff --git a/src/impls.rs b/src/impls.rs
index eac4700..7ae4510 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -667,6 +667,14 @@ mod bstr {
}
}
+ #[cfg(feature = "alloc")]
+ impl Clone for Box<BStr> {
+ #[inline]
+ fn clone(&self) -> Self {
+ BStr::from_boxed_bytes(self.a... | 1 | 8 | 0 |
86f878338b55d8225fa5d4d19c0024ffefcc918d | Ryan Lopopolo | 2023-02-01T16:53:13 | impl: make `Sealed` super trait impossible to export
The `Sealed` trait in `crate::ext_slice` and `crate::ext_vec` is marked
`pub` and is reachable from the crate root, which means there is a
(small) risk the trait may be accidentally exported as public API.
The sealed trait trick works so long as the trait is ma... | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index 70f94e2..91af450 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -101,12 +101,16 @@ impl<const N: usize> ByteSlice for [u8; N] {
/// Ensure that callers cannot implement `ByteSlice` by making an
/// umplementable trait its super trait.
-pub trait Sealed... | 2 | 15 | 7 |
79dec4301af28a81298e60279613f4d4940d2f69 | Kian-Meng Ang | 2022-12-15T16:06:27 | doc: fix typos and spelling mistakes
Found via `codespell -S *.txt -L crate,upto,fo`
PR #140 | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index 50d930a..70f94e2 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -1324,11 +1324,11 @@ pub trait ByteSlice: Sealed {
SplitReverse::new(self.as_bytes(), splitter.as_ref())
}
- /// Split this byte string at the first occurance of `splitter`.... | 4 | 10 | 10 |
898ee3fbb0c64f3a89f535ba15b385984169a752 | Ryan Lopopolo | 2022-12-15T16:00:57 | api: impl ByteSlice for [u8; N]
Fixes #86, PR #133 | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index ec52a61..50d930a 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -87,10 +87,23 @@ impl ByteSlice for [u8] {
}
}
+impl<const N: usize> ByteSlice for [u8; N] {
+ #[inline]
+ fn as_bytes(&self) -> &[u8] {
+ self
+ }
+
+ #[inline]
+ ... | 1 | 13 | 0 |
4c2e722716a5ea2938a0a02bbd3ff5760eba72a7 | Andrew Gallant | 2022-12-14T12:57:52 | impl: add Deserialize impl for Box<BStr>
This is meant to be analogous to the Deserialize impl for Box<str>
provided by Serde itself.
Closes #142 | diff --git a/src/impls.rs b/src/impls.rs
index 669aee6..eac4700 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -787,14 +787,14 @@ mod bstr_serde {
mod bstring_serde {
use core::{cmp, fmt};
- use alloc::{string::String, vec::Vec};
+ use alloc::{boxed::Box, string::String, vec::Vec};
use serde::{
... | 1 | 73 | 2 |
9d3784c4afa7ac572f15a764a8e70c7251dad27d | Sebastian Thiel | 2022-09-12T13:48:53 | serde: make traits available once again
In the serde feature shuffling leading up to 1.0, it turns out
that the old feature names were not fully replaced in the
source. As a result, enabling the 'serde' feature didn't actually
provide the 'serde' impls as one would expect.
PR #134 | diff --git a/src/impls.rs b/src/impls.rs
index 673f751..669aee6 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -725,7 +725,7 @@ mod bstr {
impl_partial_ord!(&'a BStr, String);
}
-#[cfg(feature = "serde1-core")]
+#[cfg(feature = "serde")]
mod bstr_serde {
use core::fmt;
@@ -783,7 +783,7 @@ mod bstr_serd... | 1 | 2 | 2 |
ea06e5be5550934d00b9be5575b0936d42a55ed5 | Andrew Gallant | 2022-09-09T12:37:11 | bench: remove lock file
The 'bench' crate was added to the bstr workspace, so now there is no
lock file. Which seems kind of bad to be honest. I don't usually commit
lock files for libraries, but do for their benchmarks.
Let's see how far we get with this and if any problems appear.
Fixes #131 | diff --git a/bench/Cargo.lock b/bench/Cargo.lock
deleted file mode 100644
index f668a2f..0000000
--- a/bench/Cargo.lock
+++ /dev/null
@@ -1,672 +0,0 @@
-# This file is automatically @generated by Cargo.
-# It is not intended for manual editing.
-version = 3
-
-[[package]]
-name = "anyhow"
-version = "1.0.26"
-source = ... | 1 | 0 | 672 |
6ec5f562db5d0da2056e1555cd51631802e25559 | Andrew Gallant | 2022-09-07T16:57:53 | BREAKING: api: remove ByteSlice::copy_within_str
Now slice slice::copy_within exists, there's no need for this routine. | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index e7e815c..ec52a61 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -1,4 +1,4 @@
-use core::{iter, ops, ptr, slice, str};
+use core::{iter, slice, str};
#[cfg(all(feature = "alloc", feature = "unicode"))]
use alloc::vec;
@@ -3013,69 +3013,6 @@ pub trait By... | 1 | 1 | 96 |
6df1c9db1e213250e965fa57926d62f3dc64f9e3 | Andrew Gallant | 2022-09-07T01:06:55 | unicode: add ASCII optimization for grapheme segmenter
This helps quite a bit on text that is mostly ASCII, and probably
doesn't hurt too much in text that is mostly non-ASCII.
We should re-litigate this once regex-automata 0.3 is out. The new API
will have more knobs we can turn. | diff --git a/src/unicode/grapheme.rs b/src/unicode/grapheme.rs
index ae07104..13b730c 100644
--- a/src/unicode/grapheme.rs
+++ b/src/unicode/grapheme.rs
@@ -195,6 +195,22 @@ impl<'a> DoubleEndedIterator for GraphemeIndices<'a> {
pub fn decode_grapheme(bs: &[u8]) -> (&str, usize) {
if bs.is_empty() {
("",... | 1 | 16 | 0 |
635e0f6e7d87f250582f5dacd259ccbe9d2c80ea | David Tolnay | 2022-09-03T17:54:39 | unicode: regenerate DFAs to make use of once_cell
The latest version of ucd-generate now uses once_cell
instead of lazy_static. So we re-generate the DFAs to
bring in that change and drop the lazy_static dependency.
Closes #124 | diff --git a/Cargo.toml b/Cargo.toml
index 727cfa9..ac4eb9e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -25,12 +25,12 @@ bench = false
default = ["std", "unicode"]
std = ["alloc", "memchr/std", "serde?/std"]
alloc = ["serde?/alloc"]
-unicode = ["dep:lazy_static", "dep:regex-automata"]
+unicode = ["dep:once_cell", "d... | 9 | 82 | 114 |
2b1bd053b550c546de18ad62ca615c27782c8df1 | Alex Touchet | 2022-09-03T17:36:35 | cargo: set rust-version to 1.60.0
Now that are our MSRV is high enough, we
can more effectively communicate what our
MSRV is.
PR #128 | diff --git a/Cargo.toml b/Cargo.toml
index 74a31b5..727cfa9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,7 @@ license = "MIT OR Apache-2.0"
categories = ["text-processing", "encoding"]
exclude = ["/.github"]
edition = "2021"
+rust-version = "1.60"
resolver = "2"
[workspace] | 1 | 1 | 0 |
6beae06b3ec6e2a331ce2cf701a2d378c8b9f0d2 | Ryan Lopopolo | 2022-09-03T17:25:12 | api: add BString::new and make it const
Closes #73 | diff --git a/src/bstring.rs b/src/bstring.rs
index 49eaa78..d144b1d 100644
--- a/src/bstring.rs
+++ b/src/bstring.rs
@@ -44,8 +44,25 @@ pub struct BString {
}
impl BString {
+ /// Constructs a new `BString` from the given [`Vec`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use bstr::BString;
+ ... | 1 | 18 | 1 |
fb46d55555b8bed35b8e3960fd75cb70f019f9d9 | Andrew Gallant | 2022-09-02T15:13:58 | 1.0.0-pre.3 | diff --git a/Cargo.toml b/Cargo.toml
index a996da0..74a31b5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bstr"
-version = "1.0.0-pre.2" #:version
+version = "1.0.0-pre.3" #:version
authors = ["Andrew Gallant <jamslam@gmail.com>"]
description = "A string type that is not required to b... | 1 | 1 | 1 |
2330bcfe1586a95ad6a05e57035d31d0253564c2 | Andrew Gallant | 2022-09-02T14:31:24 | BREAKING: api: tweak wording of OsStr/Path conversions
This slightly tweaks the documentation of the various OsStr/Path
conversion routines to cover the possible future where `OsStr::as_bytes`
(and probably also `OsStr::from_bytes`) exists. Namely, the point of
these routines was always to get at the underlying byte r... | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index b0287e9..e7e815c 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -153,11 +153,12 @@ pub trait ByteSlice: Sealed {
/// Create an immutable byte string from an OS string slice.
///
- /// On Unix, this always succeeds and is zero cost. On non-Un... | 2 | 76 | 61 |
3fab997007ac1d97e6965dff226437408d5c1bf8 | Andrew Gallant | 2022-09-02T13:55:22 | doc: mention the 'os_str_bytes' crate
Closes #116 | diff --git a/src/lib.rs b/src/lib.rs
index 5adc903..1acda0f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -322,7 +322,8 @@ they can do:
by accessing their underlying 16-bit integer representation. Unfortunately,
this isn't zero cost (it introduces a second WTF-8 decoding step) and it's
not clear this is a goo... | 1 | 2 | 1 |
140831a936bc560308b3ed7c0439b509f2a679d5 | Andrew Gallant | 2022-09-02T12:39:48 | safety: don't use integer-to-pointer casts
Miri warns about this, so we fix it. I have no particular attachment to
integer-to-pointer casts, and it seems like the tide might be shifting
against them. Since we don't need an integer-to-pointer cast here, we
drop it. I believe it was written the way it was (from the 'mem... | diff --git a/src/byteset/scalar.rs b/src/byteset/scalar.rs
index a2fcb00..28bff67 100644
--- a/src/byteset/scalar.rs
+++ b/src/byteset/scalar.rs
@@ -82,7 +82,7 @@ pub fn inv_memrchr(n1: u8, haystack: &[u8]) -> Option<usize> {
return reverse_search(start_ptr, end_ptr, ptr, confirm);
}
- pt... | 1 | 1 | 1 |
14af7d3056060e1dd22e1433d95eaed82bbcd39a | Andrew Gallant | 2022-09-02T12:39:17 | safety: compute pointers correctly
Previously, we were using 'end_ptr' by computing a zero-length pointer
by offseting from the end of the haystack. But for pointer provenance
reasons, it is more correct to computer the end pointer by adding to the
start pointer.
I don't believe this is necessary for the forward case... | diff --git a/src/byteset/scalar.rs b/src/byteset/scalar.rs
index ab2c609..a2fcb00 100644
--- a/src/byteset/scalar.rs
+++ b/src/byteset/scalar.rs
@@ -28,10 +28,11 @@ pub fn inv_memchr(n1: u8, haystack: &[u8]) -> Option<usize> {
let loop_size = cmp::min(LOOP_SIZE, haystack.len());
let align = USIZE_BYTES - 1;
... | 1 | 6 | 4 |
4a21319b617f7e7b7f9271b5799098bcc9f0569d | Ben Kimock | 2022-08-01T23:15:16 | safety: conform to stacked borrows
When using 'get_unchecked' twice where one is a mutable borrow, it ends
up creating UB under the "stacked borrows" model. Which isn't adopted
yet. Still, it seems likely that it will? So we fix it by deriving both
pointers to 'ptr::copy' from the same 'get_unchecked_mut' call.
Close... | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index 2cc9649..b0287e9 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -3063,11 +3063,8 @@ pub trait ByteSlice: Sealed {
// Finally, we are only dealing with u8 data, which is Copy, which
// means we can copy without worrying about ownership/des... | 1 | 2 | 5 |
0ee9b5e9c8c81020ac93de75f93e26664a779c42 | Andrew Gallant | 2022-09-02T12:10:52 | tests: make it tractable to run Miri
We make an absolute mess of our tests so that 'cargo miri test' will
complete in reasonable time. I hate this, but Miri is worth it.
Ref #121 | diff --git a/src/ascii.rs b/src/ascii.rs
index bb2b679..259d41f 100644
--- a/src/ascii.rs
+++ b/src/ascii.rs
@@ -23,18 +23,18 @@ use core::mem;
// means we can effectively skip the _mm_cmpeq_epi8 step and jump straight to
// _mm_movemask_epi8.
-#[cfg(any(test, not(target_arch = "x86_64")))]
+#[cfg(any(test, miri, n... | 8 | 46 | 15 |
c93a03fe95703582dd90b6c0c40df4d5b196d7c6 | Andrew Gallant | 2022-07-14T14:49:06 | 1.0.0-pre.2 | diff --git a/Cargo.toml b/Cargo.toml
index 42488bb..d0af6c0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bstr"
-version = "1.0.0-pre.1" #:version
+version = "1.0.0-pre.2" #:version
authors = ["Andrew Gallant <jamslam@gmail.com>"]
description = "A string type that is not required to b... | 1 | 1 | 1 |
16c97d5e40619f11b34aa671cd3f5e2065031f51 | Andrew Gallant | 2022-07-14T14:38:52 | doc: enable 'doc_auto_cfg' on docs.rs
This should make it easier to see which APIs need to have certain
features enabled.
This unfortunately is not perfect, which is probably why it's unstable.
For example, it doesn't show that types like 'Graphemes' are only
available with the 'unicode' feature enabled, presumably b... | diff --git a/Cargo.toml b/Cargo.toml
index 552548e..42488bb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -39,6 +39,19 @@ quickcheck = { version = "1", default-features = false }
ucd-parse = "0.1.3"
unicode-segmentation = "1.2.1"
+[package.metadata.docs.rs]
+# We want to document all features.
+all-features = true
+#... | 2 | 14 | 0 |
b89d9956c9f0c97d301ffc6351a8b41cefa40edd | Andrew Gallant | 2022-07-11T15:43:51 | api: add BStr::new
This adds a convenience constructor for building a BStr slice directly
from anything that impls AsRef<[u8]>. This is analogous to, e.g.,
Path::new from std.
While this constructor is redundant, it is often convenient because of
its concreteness. Alternatives rely on generics via trait impls, which
... | diff --git a/src/bstr.rs b/src/bstr.rs
index c451384..5036f06 100644
--- a/src/bstr.rs
+++ b/src/bstr.rs
@@ -36,8 +36,31 @@ pub struct BStr {
}
impl BStr {
+ /// Directly creates a `BStr` slice from anything that can be converted
+ /// to a byte slice.
+ ///
+ /// This is very similar to the [`B`](crate... | 1 | 24 | 1 |
f078008b545f822ce4ef964e895c6c7c662340d3 | Andrew Gallant | 2022-07-11T15:00:44 | BREAKING: change methods on BufReadExt to take '&mut self'
Previously, they consumed 'self', but there is no particular reason why
they need to do that. Instead, we can borrow self mutably.
The two methods that return iterators do continue to consume 'self'
though, which matches the style used by 'std' for 'BufRead'. | diff --git a/bench/src/bench.rs b/bench/src/bench.rs
index 3fa5ae0..3f25438 100644
--- a/bench/src/bench.rs
+++ b/bench/src/bench.rs
@@ -244,7 +244,7 @@ fn sentences(c: &mut Criterion) {
fn byte_lines(c: &mut Criterion) {
use bstr::io::BufReadExt;
- let corpus = SUBTITLE_EN_HUGE;
+ let mut corpus = SUBTIT... | 2 | 11 | 11 |
9d74d1cd7a3c77f551e760ebdde6e869905818d3 | Tethys Svensson | 2022-07-10T16:50:25 | api: add TryFrom impls between bstrs and strings
The only reason these didn't exist is probably because I built bstr
before (or too close to) when TryFrom was stabilized. But TryFrom has
been available for quite some time, so it's good sense to add these
impls now.
Closes #112 | diff --git a/src/impls.rs b/src/impls.rs
index 9665f13..f06fa4c 100644
--- a/src/impls.rs
+++ b/src/impls.rs
@@ -61,7 +61,9 @@ macro_rules! impl_partial_ord {
#[cfg(feature = "alloc")]
mod bstring {
- use core::{cmp::Ordering, fmt, iter::FromIterator, ops};
+ use core::{
+ cmp::Ordering, convert::TryFr... | 1 | 44 | 3 |
7519aa66d1134136b3ad11619c5111a4070100cc | Andrew Gallant | 2022-07-11T14:51:27 | impls: make BString completely opaque
Previously we were accessing BString's inner field. This commit changes
it so that everyone is forced to go through a method. Honestly, it's
kind of a questionable change, but I think I stylistically prefer this. | diff --git a/src/bstring.rs b/src/bstring.rs
index dbd188b..49eaa78 100644
--- a/src/bstring.rs
+++ b/src/bstring.rs
@@ -40,15 +40,25 @@ use crate::bstr::BStr;
/// region of memory containing the bytes, a length and a capacity.
#[derive(Clone, Hash)]
pub struct BString {
- pub(crate) bytes: Vec<u8>,
+ bytes: V... | 2 | 34 | 9 |
492952f68c3ee0cd7d7c5148143bb9001a45a03e | Tethys Svensson | 2022-07-10T18:39:03 | api: impl Clone for Utf8Error
This matches what std::str::Utf8Error has, and it seems like a common
sense impl.
We do not add a 'Copy' impl however, since that seems like a backcompat
hazard. Although, it does seem unlikely that this error type will ever
*not* be 'Copy', it's not clear to me that 'Copy' makes semanti... | diff --git a/src/utf8.rs b/src/utf8.rs
index 12425df..7c0d39d 100644
--- a/src/utf8.rs
+++ b/src/utf8.rs
@@ -402,7 +402,7 @@ impl<'a> ::core::iter::FusedIterator for Utf8Chunks<'a> {}
/// assert_eq!(err.valid_up_to(), 6);
/// assert_eq!(err.error_len(), Some(1));
/// ```
-#[derive(Debug, Eq, PartialEq)]
+#[derive(Cl... | 1 | 1 | 1 |
1efef563d6c389ed1b05807cdd02f7bbf87fa25d | Andrew Gallant | 2022-07-06T00:21:08 | style: use 'pub(crate)' instead of 'pub'
It's nice to reserve 'pub' strictly for things that are part of the
public API, as a way of making it easy to see which things are and
aren't part of the API.
I'm sure there are more 'pub' things that we should make 'pub(crate)',
but this one stood out to me. | diff --git a/src/tests.rs b/src/tests.rs
index f4179fd..03a4461 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -6,7 +6,7 @@
///
/// The first element in each tuple is the expected result of lossy decoding,
/// while the second element is the input given.
-pub const LOSSY_TESTS: &[(&str, &[u8])] = &[
+pub(crate) con... | 1 | 1 | 1 |
c426700b5fefced58f9a3d3ab09dbfe4c074ed01 | Andrew Gallant | 2022-07-06T00:17:46 | style: switch import style
This switches over to using as fewer 'use' statements. We don't go with
the minimal number though, since I still find it useful to split 'use'
statements into logical blocks: core, alloc, std, third party, crate. | diff --git a/src/bstr.rs b/src/bstr.rs
index 689a344..c451384 100644
--- a/src/bstr.rs
+++ b/src/bstr.rs
@@ -1,6 +1,7 @@
+use core::mem;
+
#[cfg(feature = "alloc")]
use alloc::boxed::Box;
-use core::mem;
/// A wrapper for `&[u8]` that provides convenient string oriented trait impls.
///
diff --git a/src/byteset/m... | 14 | 111 | 110 |
bba1fab2fc85ce1142a958cbca9c8f6127d86e00 | Andrew Gallant | 2022-07-05T23:44:57 | BREAKING: put 'ByteSlice::fields' behind 'unicode' feature
It currently uses 'char::is_whitespace', but this is more of an
implementation detail. While 'char::is_whitespace' is available in
'core', it's plausible that we might use our own data some data. In
particular, 'trim' already uses its own data.
I believe this... | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index 2efcaaf..7bc27c2 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -1053,8 +1053,9 @@ pub trait ByteSlice: Sealed {
byteset::rfind_not(self.as_bytes(), byteset.as_ref())
}
- /// Returns an iterator over the fields in a byte string, separate... | 2 | 14 | 5 |
6dcbd07da4b969afc2753c4ec830dc945560d0b1 | Andrew Gallant | 2022-07-05T23:32:50 | doc: move 'r?split_once_str' routines
Our pattern has been to group forward/reverse APIs together, but the
split_once APIs were put between 'split_str' and 'rsplit_str'. So we
move them both below 'rsplit_str'. | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index a6351c8..2efcaaf 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -1208,94 +1208,6 @@ pub trait ByteSlice: Sealed {
Split::new(self.as_bytes(), splitter.as_ref())
}
- /// Split this byte string at the first occurance of `splitter`.
- //... | 1 | 88 | 88 |
893ce3c13d14d739e44fb4c59b523f1fe1cba2e0 | Andrew Gallant | 2022-07-05T23:30:32 | BREAKING: make splits and find honestly represent their lifetimes
In a few places I must have got lazy when defining the iterator types
and forced haystacks and needles/splitters to always have the same
lifetime. This works in most cases, but #45 shows a case where it breaks
down. To fix it, we just make sure we repre... | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index fad3f4b..a6351c8 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -762,10 +762,10 @@ pub trait ByteSlice: Sealed {
/// assert_eq!(matches, vec![0]);
/// ```
#[inline]
- fn find_iter<'a, B: ?Sized + AsRef<[u8]>>(
- &'a self,
- ... | 1 | 84 | 83 |
3d6e49f353e2f51d09affaa6a6bfcd2b90475097 | Andrew Gallant | 2022-07-05T23:20:06 | doc: add examples using an empty byteset
This doesn't change any behavior (I was wrong in #87), but instead
clarifies that empty bytesets are valid and never match anything.
Fixes #87 | diff --git a/src/ext_slice.rs b/src/ext_slice.rs
index 2172d47..fad3f4b 100644
--- a/src/ext_slice.rs
+++ b/src/ext_slice.rs
@@ -929,14 +929,17 @@ pub trait ByteSlice: Sealed {
/// assert_eq!(b"foo bar baz".find_byteset(b"zr"), Some(6));
/// assert_eq!(b"foo baz bar".find_byteset(b"bzr"), Some(4));
/// a... | 1 | 9 | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.