From 0dbf2df35d4bde68bce128fb686293ea81180ad8 Mon Sep 17 00:00:00 2001 From: mxsm Date: Tue, 19 Nov 2024 09:47:32 +0000 Subject: [PATCH] =?UTF-8?q?[ISSUE=20#59]=E2=9A=A1=EF=B8=8FAdd=20#[inline]?= =?UTF-8?q?=20for=20some=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cheetah_string.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cheetah_string.rs b/src/cheetah_string.rs index 36c3d98..2d5367a 100644 --- a/src/cheetah_string.rs +++ b/src/cheetah_string.rs @@ -103,6 +103,7 @@ impl From for CheetahString { } impl<'a> FromIterator<&'a char> for CheetahString { + #[inline] fn from_iter>(iter: T) -> CheetahString { let mut buf = String::new(); buf.extend(iter); @@ -152,6 +153,7 @@ impl From<&CheetahString> for CheetahString { } impl From for String { + #[inline] fn from(s: CheetahString) -> Self { match s { CheetahString { @@ -184,24 +186,28 @@ impl Deref for CheetahString { } impl AsRef for CheetahString { + #[inline] fn as_ref(&self) -> &str { self.as_str() } } impl AsRef<[u8]> for CheetahString { + #[inline] fn as_ref(&self) -> &[u8] { self.as_bytes() } } impl AsRef for CheetahString { + #[inline] fn as_ref(&self) -> &CheetahString { self } } impl From<&String> for CheetahString { + #[inline] fn from(s: &String) -> Self { CheetahString::from_slice(s) } @@ -209,7 +215,7 @@ impl From<&String> for CheetahString { impl CheetahString { #[inline] - pub fn empty() -> Self { + pub const fn empty() -> Self { CheetahString { inner: InnerString::Empty, } @@ -319,48 +325,56 @@ impl CheetahString { } impl PartialEq for CheetahString { + #[inline] fn eq(&self, other: &Self) -> bool { self.as_str() == other.as_str() } } impl PartialEq for CheetahString { + #[inline] fn eq(&self, other: &str) -> bool { self.as_str() == other } } impl PartialEq for CheetahString { + #[inline] fn eq(&self, other: &String) -> bool { self.as_str() == other.as_str() } } impl PartialEq> for CheetahString { + #[inline] fn eq(&self, other: &Vec) -> bool { self.as_bytes() == other.as_slice() } } impl<'a> PartialEq<&'a str> for CheetahString { + #[inline] fn eq(&self, other: &&'a str) -> bool { self.as_str() == *other } } impl PartialEq for str { + #[inline] fn eq(&self, other: &CheetahString) -> bool { self == other.as_str() } } impl PartialEq for String { + #[inline] fn eq(&self, other: &CheetahString) -> bool { self.as_str() == other.as_str() } } impl PartialEq for &str { + #[inline] fn eq(&self, other: &CheetahString) -> bool { *self == other.as_str() } @@ -369,36 +383,42 @@ impl PartialEq for &str { impl Eq for CheetahString {} impl PartialOrd for CheetahString { + #[inline] fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for CheetahString { + #[inline] fn cmp(&self, other: &Self) -> Ordering { self.as_str().cmp(other.as_str()) } } impl Hash for CheetahString { + #[inline] fn hash(&self, state: &mut H) { self.as_str().hash(state); } } impl Display for CheetahString { + #[inline] fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } } impl std::fmt::Debug for CheetahString { + #[inline] fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fmt::Debug::fmt(self.as_str(), f) } } impl Borrow for CheetahString { + #[inline] fn borrow(&self) -> &str { self.as_str() }