Skip to content

Commit e8f90b1

Browse files
committed
Try to avoid string copies
1 parent 4398750 commit e8f90b1

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

src/librustdoc/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl Options {
474474
};
475475

476476
let mut id_map = html::markdown::IdMap::new();
477-
id_map.populate(html::render::initial_ids());
477+
id_map.populate(&html::render::INITIAL_IDS);
478478
let external_html = match ExternalHtml::load(
479479
&matches.opt_strs("html-in-header"),
480480
&matches.opt_strs("html-before-content"),

src/librustdoc/html/markdown.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ impl IdMap {
13321332
IdMap { map: init_id_map() }
13331333
}
13341334

1335-
crate fn populate<I: IntoIterator<Item = String>>(&mut self, ids: I) {
1335+
crate fn populate<I: IntoIterator<Item = S>, S: AsRef<str> + ToString>(&mut self, ids: I) {
13361336
for id in ids {
13371337
let _ = self.derive(id);
13381338
}
@@ -1342,11 +1342,11 @@ impl IdMap {
13421342
self.map = init_id_map();
13431343
}
13441344

1345-
crate fn derive(&mut self, candidate: String) -> String {
1346-
let id = match self.map.get_mut(&candidate) {
1347-
None => candidate,
1345+
crate fn derive<S: AsRef<str> + ToString>(&mut self, candidate: S) -> String {
1346+
let id = match self.map.get_mut(candidate.as_ref()) {
1347+
None => candidate.to_string(),
13481348
Some(a) => {
1349-
let id = format!("{}-{}", candidate, *a);
1349+
let id = format!("{}-{}", candidate.as_ref(), *a);
13501350
*a += 1;
13511351
id
13521352
}

src/librustdoc/html/render/mod.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -359,28 +359,24 @@ crate struct StylePath {
359359

360360
thread_local!(crate static CURRENT_DEPTH: Cell<usize> = Cell::new(0));
361361

362-
crate fn initial_ids() -> Vec<String> {
363-
[
364-
"main",
365-
"search",
366-
"help",
367-
"TOC",
368-
"render-detail",
369-
"associated-types",
370-
"associated-const",
371-
"required-methods",
372-
"provided-methods",
373-
"implementors",
374-
"synthetic-implementors",
375-
"implementors-list",
376-
"synthetic-implementors-list",
377-
"methods",
378-
"implementations",
379-
]
380-
.iter()
381-
.map(|id| (String::from(*id)))
382-
.collect()
383-
}
362+
// FIXME: make this work
363+
crate const INITIAL_IDS: [&'static str; 15] = [
364+
"main",
365+
"search",
366+
"help",
367+
"TOC",
368+
"render-detail",
369+
"associated-types",
370+
"associated-const",
371+
"required-methods",
372+
"provided-methods",
373+
"implementors",
374+
"synthetic-implementors",
375+
"implementors-list",
376+
"synthetic-implementors-list",
377+
"methods",
378+
"implementations",
379+
];
384380

385381
/// Generates the documentation for `crate` into the directory `dst`
386382
impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
@@ -1581,7 +1577,7 @@ impl Context<'_> {
15811577

15821578
{
15831579
self.id_map.borrow_mut().reset();
1584-
self.id_map.borrow_mut().populate(initial_ids());
1580+
self.id_map.borrow_mut().populate(&INITIAL_IDS);
15851581
}
15861582

15871583
if !self.render_redirect_pages {

0 commit comments

Comments
 (0)