Skip to content

Commit

Permalink
feat: prefer inline in slice_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWhiteWu committed Sep 5, 2024
1 parent f5ea63e commit 68ddbea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "faststr"
version = "0.2.22"
version = "0.2.23"
authors = ["Volo Team <[email protected]>"]
edition = "2021"
description = "Faststr is a string library that reduces the cost of clone."
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,14 @@ impl FastStr {
}

/// Return a new `FastStr` that represents a subset of the current string.
///
/// Note: If the subset is small enough, it will be inlined.
#[inline(always)]
pub fn slice_ref(&self, subset: &str) -> Self {
if subset.len() <= INLINE_CAP {
// Safety: we have checked the length of subset <= `INLINE_CAP`.
return Self(unsafe { Repr::new_inline_impl(subset) });
}
Self(self.0.slice_ref(subset.as_bytes()))
}

Expand Down

0 comments on commit 68ddbea

Please sign in to comment.