Skip to content

Commit b420d92

Browse files
committed
Auto merge of rust-lang#132870 - Noratrieb:inline-int-parsing, r=tgross35
`#[inline]` integer parsing functions This improves the performance of `str::parse` into integers. Before: ``` compare fastest │ slowest │ median │ mean │ samples │ iters ╰─ std │ │ │ │ │ ├─ 328920585 10.23 ns │ 24.8 ns │ 10.34 ns │ 10.48 ns │ 100 │ 25600 ├─ 3255 8.551 ns │ 8.59 ns │ 8.551 ns │ 8.56 ns │ 100 │ 25600 ╰─ 5 7.847 ns │ 7.887 ns │ 7.847 ns │ 7.853 ns │ 100 │ 25600 ``` After: ``` compare fastest │ slowest │ median │ mean │ samples │ iters ╰─ std │ │ │ │ │ ├─ 328920585 8.316 ns │ 23.7 ns │ 8.355 ns │ 8.491 ns │ 100 │ 25600 ├─ 3255 4.566 ns │ 4.588 ns │ 4.586 ns │ 4.576 ns │ 100 │ 51200 ╰─ 5 2.877 ns │ 3.697 ns │ 2.896 ns │ 2.945 ns │ 100 │ 102400 ``` Benchmark: ```rust fn std(input: &str) -> Result<u64, ParseIntError> { input.parse() } ```
2 parents f7273e0 + fc8c16e commit b420d92

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

library/core/src/num/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ macro_rules! from_str_radix_int_impl {
14331433
#[stable(feature = "rust1", since = "1.0.0")]
14341434
impl FromStr for $t {
14351435
type Err = ParseIntError;
1436+
#[inline]
14361437
fn from_str(src: &str) -> Result<Self, ParseIntError> {
14371438
<$t>::from_str_radix(src, 10)
14381439
}
@@ -1505,6 +1506,7 @@ macro_rules! from_str_radix {
15051506
/// ```
15061507
#[stable(feature = "rust1", since = "1.0.0")]
15071508
#[rustc_const_stable(feature = "const_int_from_str", since = "1.82.0")]
1509+
#[inline]
15081510
pub const fn from_str_radix(src: &str, radix: u32) -> Result<$int_ty, ParseIntError> {
15091511
use self::IntErrorKind::*;
15101512
use self::ParseIntError as PIE;
@@ -1649,6 +1651,7 @@ macro_rules! from_str_radix_size_impl {
16491651
/// ```
16501652
#[stable(feature = "rust1", since = "1.0.0")]
16511653
#[rustc_const_stable(feature = "const_int_from_str", since = "1.82.0")]
1654+
#[inline]
16521655
pub const fn from_str_radix(src: &str, radix: u32) -> Result<$size, ParseIntError> {
16531656
match <$t>::from_str_radix(src, radix) {
16541657
Ok(x) => Ok(x as $size),

0 commit comments

Comments
 (0)