Skip to content

Commit b570900

Browse files
authored
[ISSUE #59]⚡️Add #[inline] for some methods (#60)
1 parent 2075165 commit b570900

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/cheetah_string.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl From<char> for CheetahString {
103103
}
104104

105105
impl<'a> FromIterator<&'a char> for CheetahString {
106+
#[inline]
106107
fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> CheetahString {
107108
let mut buf = String::new();
108109
buf.extend(iter);
@@ -152,6 +153,7 @@ impl From<&CheetahString> for CheetahString {
152153
}
153154

154155
impl From<CheetahString> for String {
156+
#[inline]
155157
fn from(s: CheetahString) -> Self {
156158
match s {
157159
CheetahString {
@@ -184,32 +186,36 @@ impl Deref for CheetahString {
184186
}
185187

186188
impl AsRef<str> for CheetahString {
189+
#[inline]
187190
fn as_ref(&self) -> &str {
188191
self.as_str()
189192
}
190193
}
191194

192195
impl AsRef<[u8]> for CheetahString {
196+
#[inline]
193197
fn as_ref(&self) -> &[u8] {
194198
self.as_bytes()
195199
}
196200
}
197201

198202
impl AsRef<CheetahString> for CheetahString {
203+
#[inline]
199204
fn as_ref(&self) -> &CheetahString {
200205
self
201206
}
202207
}
203208

204209
impl From<&String> for CheetahString {
210+
#[inline]
205211
fn from(s: &String) -> Self {
206212
CheetahString::from_slice(s)
207213
}
208214
}
209215

210216
impl CheetahString {
211217
#[inline]
212-
pub fn empty() -> Self {
218+
pub const fn empty() -> Self {
213219
CheetahString {
214220
inner: InnerString::Empty,
215221
}
@@ -319,48 +325,56 @@ impl CheetahString {
319325
}
320326

321327
impl PartialEq for CheetahString {
328+
#[inline]
322329
fn eq(&self, other: &Self) -> bool {
323330
self.as_str() == other.as_str()
324331
}
325332
}
326333

327334
impl PartialEq<str> for CheetahString {
335+
#[inline]
328336
fn eq(&self, other: &str) -> bool {
329337
self.as_str() == other
330338
}
331339
}
332340

333341
impl PartialEq<String> for CheetahString {
342+
#[inline]
334343
fn eq(&self, other: &String) -> bool {
335344
self.as_str() == other.as_str()
336345
}
337346
}
338347

339348
impl PartialEq<Vec<u8>> for CheetahString {
349+
#[inline]
340350
fn eq(&self, other: &Vec<u8>) -> bool {
341351
self.as_bytes() == other.as_slice()
342352
}
343353
}
344354

345355
impl<'a> PartialEq<&'a str> for CheetahString {
356+
#[inline]
346357
fn eq(&self, other: &&'a str) -> bool {
347358
self.as_str() == *other
348359
}
349360
}
350361

351362
impl PartialEq<CheetahString> for str {
363+
#[inline]
352364
fn eq(&self, other: &CheetahString) -> bool {
353365
self == other.as_str()
354366
}
355367
}
356368

357369
impl PartialEq<CheetahString> for String {
370+
#[inline]
358371
fn eq(&self, other: &CheetahString) -> bool {
359372
self.as_str() == other.as_str()
360373
}
361374
}
362375

363376
impl PartialEq<CheetahString> for &str {
377+
#[inline]
364378
fn eq(&self, other: &CheetahString) -> bool {
365379
*self == other.as_str()
366380
}
@@ -369,36 +383,42 @@ impl PartialEq<CheetahString> for &str {
369383
impl Eq for CheetahString {}
370384

371385
impl PartialOrd for CheetahString {
386+
#[inline]
372387
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
373388
Some(self.cmp(other))
374389
}
375390
}
376391

377392
impl Ord for CheetahString {
393+
#[inline]
378394
fn cmp(&self, other: &Self) -> Ordering {
379395
self.as_str().cmp(other.as_str())
380396
}
381397
}
382398

383399
impl Hash for CheetahString {
400+
#[inline]
384401
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
385402
self.as_str().hash(state);
386403
}
387404
}
388405

389406
impl Display for CheetahString {
407+
#[inline]
390408
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
391409
self.as_str().fmt(f)
392410
}
393411
}
394412

395413
impl std::fmt::Debug for CheetahString {
414+
#[inline]
396415
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
397416
fmt::Debug::fmt(self.as_str(), f)
398417
}
399418
}
400419

401420
impl Borrow<str> for CheetahString {
421+
#[inline]
402422
fn borrow(&self) -> &str {
403423
self.as_str()
404424
}

0 commit comments

Comments
 (0)