Skip to content

Commit ad1c0c5

Browse files
committed
Rollup merge of rust-lang#25158 - koute:master, r=alexcrichton
I was profiling my code again and this time AsRef<str> for String was eating up a considerable chunk of my runtime; adding the inline annotation made the program run almost twice as fast! While I was at it I also added the annotation to other implementations of AsRef as well as AsMut.
2 parents 371eb87 + a168dba commit ad1c0c5

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/libcollections/string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ impl<T: fmt::Display + ?Sized> ToString for T {
10521052

10531053
#[stable(feature = "rust1", since = "1.0.0")]
10541054
impl AsRef<str> for String {
1055+
#[inline]
10551056
fn as_ref(&self) -> &str {
10561057
self
10571058
}

src/libcore/convert.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ impl<T> AsMut<[T]> for [T] {
173173

174174
#[stable(feature = "rust1", since = "1.0.0")]
175175
impl AsRef<str> for str {
176+
#[inline]
176177
fn as_ref(&self) -> &str {
177178
self
178179
}

0 commit comments

Comments
 (0)