Skip to content

Commit 52d5e43

Browse files
tormolThomas Bahn
authored andcommitted
Mark most short functions with #[inline]
I just learned that it's required for cross-crate inlining without LTO.
1 parent 8f24ff2 commit 52d5e43

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

src/ascii_char.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ impl AsciiChar {
299299
}
300300

301301
/// Constructs an ASCII character from a `char` or `u8` without any checks.
302+
#[inline]
302303
pub unsafe fn from_unchecked<C:ToAsciiChar>(ch: C) -> Self {
303304
ch.to_ascii_char_unchecked()
304305
}
@@ -477,6 +478,7 @@ impl AsciiChar {
477478
/// Maps letters `a`...`z` to `A`...`Z` and returns everything else unchanged.
478479
///
479480
/// A replacement for `AsciiExt::to_ascii_uppercase()`.
481+
#[inline]
480482
pub fn to_ascii_uppercase(&self) -> Self {
481483
unsafe{ match *self as u8 {
482484
b'a'...b'z' => AsciiChar::from_unchecked(self.as_byte() - (b'a' - b'A')),
@@ -488,6 +490,7 @@ impl AsciiChar {
488490
/// Maps letters `A`...`Z` to `a`...`z` and returns everything else unchanged.
489491
///
490492
/// A replacement for `AsciiExt::to_ascii_lowercase()`.
493+
#[inline]
491494
pub fn to_ascii_lowercase(&self) -> Self {
492495
unsafe{ match *self as u8 {
493496
b'A'...b'Z' => AsciiChar::from_unchecked(self.as_byte() + (b'a' - b'A')),
@@ -505,12 +508,14 @@ impl AsciiChar {
505508
}
506509

507510
impl fmt::Display for AsciiChar {
511+
#[inline]
508512
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
509513
self.as_char().fmt(f)
510514
}
511515
}
512516

513517
impl fmt::Debug for AsciiChar {
518+
#[inline]
514519
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
515520
self.as_char().fmt(f)
516521
}
@@ -525,10 +530,12 @@ impl AsciiExt for AsciiChar {
525530
true
526531
}
527532

533+
#[inline]
528534
fn to_ascii_uppercase(&self) -> AsciiChar {
529535
unsafe{ self.as_byte().to_ascii_uppercase().to_ascii_char_unchecked() }
530536
}
531537

538+
#[inline]
532539
fn to_ascii_lowercase(&self) -> AsciiChar {
533540
unsafe{ self.as_byte().to_ascii_lowercase().to_ascii_char_unchecked() }
534541
}
@@ -550,26 +557,31 @@ impl AsciiExt for AsciiChar {
550557

551558
macro_rules! impl_into_partial_eq_ord {($wider:ty, $to_wider:expr) => {
552559
impl From<AsciiChar> for $wider {
560+
#[inline]
553561
fn from(a: AsciiChar) -> $wider {
554562
$to_wider(a)
555563
}
556564
}
557565
impl PartialEq<$wider> for AsciiChar {
566+
#[inline]
558567
fn eq(&self, rhs: &$wider) -> bool {
559568
$to_wider(*self) == *rhs
560569
}
561570
}
562571
impl PartialEq<AsciiChar> for $wider {
572+
#[inline]
563573
fn eq(&self, rhs: &AsciiChar) -> bool {
564574
*self == $to_wider(*rhs)
565575
}
566576
}
567577
impl PartialOrd<$wider> for AsciiChar {
578+
#[inline]
568579
fn partial_cmp(&self, rhs: &$wider) -> Option<Ordering> {
569580
$to_wider(*self).partial_cmp(rhs)
570581
}
571582
}
572583
impl PartialOrd<AsciiChar> for $wider {
584+
#[inline]
573585
fn partial_cmp(&self, rhs: &AsciiChar) -> Option<Ordering> {
574586
self.partial_cmp(&$to_wider(*rhs))
575587
}
@@ -588,6 +600,7 @@ const ERRORMSG_CHAR: &'static str = "not an ASCII character";
588600
#[cfg(feature = "no_std")]
589601
impl ToAsciiCharError {
590602
/// Returns a description for this error, like `std::error::Error::description`.
603+
#[inline]
591604
pub fn description(&self) -> &'static str {
592605
ERRORMSG_CHAR
593606
}
@@ -607,6 +620,7 @@ impl fmt::Display for ToAsciiCharError {
607620

608621
#[cfg(not(feature = "no_std"))]
609622
impl Error for ToAsciiCharError {
623+
#[inline]
610624
fn description(&self) -> &'static str {
611625
ERRORMSG_CHAR
612626
}
@@ -621,33 +635,39 @@ pub trait ToAsciiChar {
621635
}
622636

623637
impl ToAsciiChar for AsciiChar {
638+
#[inline]
624639
fn to_ascii_char(self) -> Result<AsciiChar, ToAsciiCharError> {
625640
Ok(self)
626641
}
642+
#[inline]
627643
unsafe fn to_ascii_char_unchecked(self) -> AsciiChar {
628644
self
629645
}
630646
}
631647

632648
impl ToAsciiChar for u8 {
649+
#[inline]
633650
fn to_ascii_char(self) -> Result<AsciiChar, ToAsciiCharError> {
634651
unsafe{ if self <= 0x7F {
635652
return Ok(self.to_ascii_char_unchecked());
636653
}}
637654
Err(ToAsciiCharError(()))
638655
}
656+
#[inline]
639657
unsafe fn to_ascii_char_unchecked(self) -> AsciiChar {
640658
transmute(self)
641659
}
642660
}
643661

644662
impl ToAsciiChar for char {
663+
#[inline]
645664
fn to_ascii_char(self) -> Result<AsciiChar, ToAsciiCharError> {
646665
unsafe{ if self as u32 <= 0x7F {
647666
return Ok(self.to_ascii_char_unchecked());
648667
}}
649668
Err(ToAsciiCharError(()))
650669
}
670+
#[inline]
651671
unsafe fn to_ascii_char_unchecked(self) -> AsciiChar {
652672
(self as u8).to_ascii_char_unchecked()
653673
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy