about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/types.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/types.rs b/src/types.rs
index cd2582e66be..9d6e43c0ba4 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -43,11 +43,13 @@ pub(crate) fn rewrite_path(
 ) -> Option<String> {
     let skip_count = qself.as_ref().map_or(0, |x| x.position);
 
-    let mut result = if path.is_global() && qself.is_none() && path_context != PathContext::Import {
-        "::".to_owned()
-    } else {
-        String::new()
-    };
+    // 32 covers almost all path lengths measured when compiling core, and there isn't a big
+    // downside from allocating slightly more than necessary.
+    let mut result = String::with_capacity(32);
+
+    if path.is_global() && qself.is_none() && path_context != PathContext::Import {
+        result.push_str("::");
+    }
 
     let mut span_lo = path.span.lo();