Skip to content

Commit 675f00b

Browse files
committed
rustc/session: improve allocations
1 parent 942a796 commit 675f00b

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

src/librustc/session/config.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,10 @@ pub enum Input {
490490
}
491491

492492
impl Input {
493-
pub fn filestem(&self) -> String {
493+
pub fn filestem(&self) -> &str {
494494
match *self {
495-
Input::File(ref ifile) => ifile.file_stem().unwrap().to_str().unwrap().to_string(),
496-
Input::Str { .. } => "rust_out".to_string(),
495+
Input::File(ref ifile) => ifile.file_stem().unwrap().to_str().unwrap(),
496+
Input::Str { .. } => "rust_out",
497497
}
498498
}
499499

@@ -1406,6 +1406,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
14061406
let atomic_cas = sess.target.target.options.atomic_cas;
14071407

14081408
let mut ret = FxHashSet::default();
1409+
ret.reserve(6); // the minimum number of insertions
14091410
// Target bindings.
14101411
ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os))));
14111412
if let Some(ref fam) = sess.target.target.options.target_family {

src/librustc/session/filesearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a> FileSearch<'a> {
4141
F: FnMut(&Path, PathKind)
4242
{
4343
let mut visited_dirs = FxHashSet::default();
44-
44+
visited_dirs.reserve(self.search_paths.paths.len() + 1);
4545
for (path, kind) in self.search_paths.iter(self.kind) {
4646
f(path, kind);
4747
visited_dirs.insert(path.to_path_buf());

src/librustc/session/search_paths.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use session::{early_error, config};
1414

1515
#[derive(Clone, Debug)]
1616
pub struct SearchPaths {
17-
paths: Vec<(PathKind, PathBuf)>,
17+
crate paths: Vec<(PathKind, PathBuf)>,
1818
}
1919

2020
pub struct Iter<'a> {

src/librustc_driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ pub fn build_output_filenames(
16571657
.crate_name
16581658
.clone()
16591659
.or_else(|| attr::find_crate_name(attrs).map(|n| n.to_string()))
1660-
.unwrap_or_else(|| input.filestem());
1660+
.unwrap_or_else(|| input.filestem().to_owned());
16611661

16621662
OutputFilenames {
16631663
out_directory: dirpath,

0 commit comments

Comments
 (0)