about summary refs log tree commit diff
path: root/src/librustc_metadata
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-10-12 10:15:27 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-10-12 14:07:56 -0700
commitf05bd1b41ddda779032f4c5c8e30bf640129832f (patch)
tree20136a8f6a2215e22703c51ba54c78426c3837fe /src/librustc_metadata
parenta0ad6616fc2244eea66c6adadd35f899b170505f (diff)
parentb043e11de2eb2c60f7bfec5e15960f537b229e20 (diff)
downloadrust-f05bd1b41ddda779032f4c5c8e30bf640129832f.tar.gz
rust-f05bd1b41ddda779032f4c5c8e30bf640129832f.zip
Rollup merge of #37064 - nnethercote:read_str, r=eddyb
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/librustc_metadata')
-rw-r--r--src/librustc_metadata/decoder.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index 579a97138f2..bdb4d383cee 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -32,6 +32,7 @@ use rustc_const_math::ConstInt;
 
 use rustc::mir::repr::Mir;
 
+use std::borrow::Cow;
 use std::cell::Ref;
 use std::io;
 use std::mem;
@@ -202,7 +203,7 @@ impl<'doc, 'tcx> Decoder for DecodeContext<'doc, 'tcx> {
         read_f64 -> f64;
         read_f32 -> f32;
         read_char -> char;
-        read_str -> String;
+        read_str -> Cow<str>;
     }
 
     fn error(&mut self, err: &str) -> Self::Error {