Skip to content

Commit f93f422

Browse files
committed
Only format prefix once
1 parent 7aaf95d commit f93f422

File tree

1 file changed

+30
-27
lines changed
  • src/librustdoc/html/render

1 file changed

+30
-27
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ crate type NameDoc = (String, Option<String>);
8989

9090
crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
9191
crate::html::format::display_fn(move |f| {
92-
if !v.ends_with('/') && !v.is_empty() { write!(f, "{}/", v) } else { write!(f, "{}", v) }
92+
if !v.ends_with('/') && !v.is_empty() { write!(f, "{}/", v) } else { f.write_str(v) }
9393
})
9494
}
9595

@@ -904,12 +904,13 @@ themePicker.onblur = handleThemeButtonsBlur;
904904
let mut krates = Vec::new();
905905

906906
if path.exists() {
907+
let prefix = format!(r#"{}["{}"]"#, key, krate);
907908
for line in BufReader::new(File::open(path)?).lines() {
908909
let line = line?;
909910
if !line.starts_with(key) {
910911
continue;
911912
}
912-
if line.starts_with(&format!(r#"{}["{}"]"#, key, krate)) {
913+
if line.starts_with(&prefix) {
913914
continue;
914915
}
915916
ret.push(line.to_string());
@@ -930,12 +931,13 @@ themePicker.onblur = handleThemeButtonsBlur;
930931
let mut krates = Vec::new();
931932

932933
if path.exists() {
934+
let prefix = format!("\"{}\"", krate);
933935
for line in BufReader::new(File::open(path)?).lines() {
934936
let line = line?;
935937
if !line.starts_with('"') {
936938
continue;
937939
}
938-
if line.starts_with(&format!("\"{}\"", krate)) {
940+
if line.starts_with(&prefix) {
939941
continue;
940942
}
941943
if line.ends_with(",\\") {
@@ -1920,12 +1922,13 @@ fn document_full(
19201922
debug!("Doc block: =====\n{}\n=====", s);
19211923
render_markdown(w, cx, &*s, item.links(&cx.cache), prefix, is_hidden);
19221924
} else if !prefix.is_empty() {
1923-
write!(
1924-
w,
1925-
"<div class=\"docblock{}\">{}</div>",
1926-
if is_hidden { " hidden" } else { "" },
1927-
prefix
1928-
);
1925+
if is_hidden {
1926+
w.write_str("<div class=\"docblock hidden\">");
1927+
} else {
1928+
w.write_str("<div class=\"docblock\">");
1929+
}
1930+
w.write_str(prefix);
1931+
w.write_str("</div");
19291932
}
19301933
}
19311934

@@ -1943,11 +1946,15 @@ fn document_item_info(
19431946
) {
19441947
let item_infos = short_item_info(item, cx, parent);
19451948
if !item_infos.is_empty() {
1946-
write!(w, "<div class=\"item-info{}\">", if is_hidden { " hidden" } else { "" });
1949+
if is_hidden {
1950+
w.write_str("<div class=\"item-info hidden\">");
1951+
} else {
1952+
w.write_str("<div class=\"item-info\">");
1953+
}
19471954
for info in item_infos {
1948-
write!(w, "{}", info);
1955+
w.write_str(&info);
19491956
}
1950-
write!(w, "</div>");
1957+
w.write_str("</div>");
19511958
}
19521959
}
19531960

@@ -1970,36 +1977,32 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) {
19701977
});
19711978

19721979
if item.is_struct() {
1973-
write!(
1974-
w,
1980+
w.write_str(
19751981
"Non-exhaustive structs could have additional fields added in future. \
19761982
Therefore, non-exhaustive structs cannot be constructed in external crates \
19771983
using the traditional <code>Struct {{ .. }}</code> syntax; cannot be \
19781984
matched against without a wildcard <code>..</code>; and \
1979-
struct update syntax will not work."
1985+
struct update syntax will not work.",
19801986
);
19811987
} else if item.is_enum() {
1982-
write!(
1983-
w,
1988+
w.write_str(
19841989
"Non-exhaustive enums could have additional variants added in future. \
19851990
Therefore, when matching against variants of non-exhaustive enums, an \
1986-
extra wildcard arm must be added to account for any future variants."
1991+
extra wildcard arm must be added to account for any future variants.",
19871992
);
19881993
} else if item.is_variant() {
1989-
write!(
1990-
w,
1994+
w.write_str(
19911995
"Non-exhaustive enum variants could have additional fields added in future. \
19921996
Therefore, non-exhaustive enum variants cannot be constructed in external \
1993-
crates and cannot be matched against."
1997+
crates and cannot be matched against.",
19941998
);
19951999
} else {
1996-
write!(
1997-
w,
1998-
"This type will require a wildcard arm in any match statements or constructors."
2000+
w.write_str(
2001+
"This type will require a wildcard arm in any match statements or constructors.",
19992002
);
20002003
}
20012004

2002-
write!(w, "</div>");
2005+
w.write_str("</div>");
20032006
}
20042007
}
20052008

@@ -2136,7 +2139,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
21362139
curty = myty;
21372140
} else if myty != curty {
21382141
if curty.is_some() {
2139-
write!(w, "</table>");
2142+
w.write_str("</table>");
21402143
}
21412144
curty = myty;
21422145
let (short, name) = item_ty_to_strs(&myty.unwrap());
@@ -2168,7 +2171,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
21682171
anchor(myitem.def_id, &*name.as_str(), cx.cache())
21692172
),
21702173
}
2171-
write!(w, "</code></td></tr>");
2174+
w.write_str("</code></td></tr>");
21722175
}
21732176

21742177
clean::ImportItem(ref import) => {

0 commit comments

Comments
 (0)