diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-03-18 12:04:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-18 12:04:24 +0100 |
| commit | e81a07268b233ec6940b65444a6c32ceef28ce10 (patch) | |
| tree | 84e4bc22fb0687a31153d7d47a30864ba3fbd4d6 | |
| parent | 8417c93092fbf7974c02c19ace8a46582c97c007 (diff) | |
| parent | 8628e27da34f8b64ce4a02a6f2e74a6c4016612f (diff) | |
| download | rust-e81a07268b233ec6940b65444a6c32ceef28ce10.tar.gz rust-e81a07268b233ec6940b65444a6c32ceef28ce10.zip | |
Rollup merge of #109283 - notriddle:notriddle/visibility-to-src-with-space, r=jsha
rustdoc: reduce allocations in `visibility_to_src_with_space`
| -rw-r--r-- | src/librustdoc/html/format.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 27010b771d3..d526a8be081 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -1502,9 +1502,9 @@ pub(crate) fn visibility_to_src_with_space<'a, 'tcx: 'a>( tcx: TyCtxt<'tcx>, item_did: DefId, ) -> impl fmt::Display + 'a + Captures<'tcx> { - let to_print = match visibility { - None => String::new(), - Some(ty::Visibility::Public) => "pub ".to_owned(), + let to_print: Cow<'static, str> = match visibility { + None => "".into(), + Some(ty::Visibility::Public) => "pub ".into(), Some(ty::Visibility::Restricted(vis_did)) => { // FIXME(camelid): This may not work correctly if `item_did` is a module. // However, rustdoc currently never displays a module's @@ -1512,17 +1512,17 @@ pub(crate) fn visibility_to_src_with_space<'a, 'tcx: 'a>( let parent_module = find_nearest_parent_module(tcx, item_did); if vis_did.is_crate_root() { - "pub(crate) ".to_owned() + "pub(crate) ".into() } else if parent_module == Some(vis_did) { // `pub(in foo)` where `foo` is the parent module // is the same as no visibility modifier - String::new() + "".into() } else if parent_module.and_then(|parent| find_nearest_parent_module(tcx, parent)) == Some(vis_did) { - "pub(super) ".to_owned() + "pub(super) ".into() } else { - format!("pub(in {}) ", tcx.def_path_str(vis_did)) + format!("pub(in {}) ", tcx.def_path_str(vis_did)).into() } } }; |
