diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2016-10-10 09:07:18 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2016-10-10 10:36:35 +1100 |
| commit | b043e11de2eb2c60f7bfec5e15960f537b229e20 (patch) | |
| tree | 575489dfffc417cc045cb370a35672cd424e6b1f /src/libsyntax/parse | |
| parent | 9d4d0da7af77858f268a66ff144134945c880560 (diff) | |
| download | rust-b043e11de2eb2c60f7bfec5e15960f537b229e20.tar.gz rust-b043e11de2eb2c60f7bfec5e15960f537b229e20.zip | |
Avoid allocations in `Decoder::read_str`.
`opaque::Decoder::read_str` is very hot within `rustc` due to its use in the reading of crate metadata, and it currently returns a `String`. This commit changes it to instead return a `Cow<str>`, which avoids a heap allocation. This change reduces the number of calls to `malloc` by almost 10% in some benchmarks. This is a [breaking-change] to libserialize.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 09bc5607946..73d9695a990 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -566,7 +566,7 @@ impl PartialEq<InternedString> for str { impl Decodable for InternedString { fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> { - Ok(intern(d.read_str()?.as_ref()).as_str()) + Ok(intern(&d.read_str()?).as_str()) } } |
