]> git.lizzy.rs Git - rust.git/commitdiff
Replace a few String instances with SmolStr in completions
authorLukas Wirth <lukastw97@gmail.com>
Tue, 21 Dec 2021 15:57:16 +0000 (16:57 +0100)
committerLukas Wirth <lukastw97@gmail.com>
Tue, 21 Dec 2021 15:57:16 +0000 (16:57 +0100)
crates/ide_completion/src/render/builder_ext.rs
crates/ide_completion/src/render/enum_variant.rs
crates/ide_completion/src/render/function.rs
crates/ide_completion/src/render/type_alias.rs

index 8f8bd1dfcda4e63fbbf487d8487ba70c60ea43ff..653515fec21d67cc2d1bd06459baa392ae5ab785 100644 (file)
@@ -1,6 +1,7 @@
 //! Extensions for `Builder` structure required for item rendering.
 
 use itertools::Itertools;
+use syntax::SmolStr;
 
 use crate::{context::PathKind, item::Builder, patterns::ImmediateLocation, CompletionContext};
 
@@ -56,7 +57,7 @@ fn should_add_parens(&self, ctx: &CompletionContext) -> bool {
     pub(super) fn add_call_parens(
         &mut self,
         ctx: &CompletionContext,
-        name: String,
+        name: SmolStr,
         params: Params,
     ) -> &mut Builder {
         if !self.should_add_parens(ctx) {
index f613f0dfde2d2e42ac44755e260170dbd48f0da1..4c276a9afed0e7e9a4417ae985b16c9945243afa 100644 (file)
@@ -5,6 +5,7 @@
 use hir::{db::HirDatabase, HasAttrs, HirDisplay, StructKind};
 use ide_db::SymbolKind;
 use itertools::Itertools;
+use syntax::SmolStr;
 
 use crate::{
     item::{CompletionItem, ImportEdit},
@@ -48,10 +49,10 @@ fn render(
             false,
         ),
     };
+    let qualified_name = qualified_name.to_string();
+    let short_qualified_name: SmolStr = short_qualified_name.to_string().into();
 
-    // FIXME: ModPath::to_smol_str()?
-    let mut item =
-        CompletionItem::new(SymbolKind::Variant, ctx.source_range(), qualified_name.to_string());
+    let mut item = CompletionItem::new(SymbolKind::Variant, ctx.source_range(), qualified_name);
     item.set_documentation(variant.docs(db))
         .set_deprecated(ctx.is_deprecated(variant))
         .detail(detail(db, variant, variant_kind));
@@ -60,8 +61,6 @@ fn render(
         item.add_import(import_to_add);
     }
 
-    // FIXME: ModPath::to_smol_str()?
-    let short_qualified_name = short_qualified_name.to_string();
     if variant_kind == hir::StructKind::Tuple {
         cov_mark::hit!(inserts_parens_for_tuple_enums);
         let params = Params::Anonymous(variant.fields(db).len());
index f166b87ab631c1b0a50732258910d8ad52083608..bd46e1fefbb0eed3320cb7eb4e818731771bd406 100644 (file)
@@ -52,10 +52,9 @@ fn render(
     let name = local_name.unwrap_or_else(|| func.name(db));
     let params = params(completion, func, &func_type);
 
-    // FIXME: SmolStr?
     let call = match &func_type {
-        FuncType::Method(Some(receiver)) => format!("{}.{}", receiver, &name),
-        _ => name.to_string(),
+        FuncType::Method(Some(receiver)) => format!("{}.{}", receiver, &name).into(),
+        _ => name.to_smol_str(),
     };
     let mut item = CompletionItem::new(
         if func.self_param(db).is_some() {
@@ -66,23 +65,6 @@ fn render(
         ctx.source_range(),
         call.clone(),
     );
-    item.set_documentation(ctx.docs(func))
-        .set_deprecated(ctx.is_deprecated(func) || ctx.is_deprecated_assoc_item(func))
-        .detail(detail(db, func))
-        .add_call_parens(completion, call.clone(), params);
-
-    if import_to_add.is_none() {
-        if let Some(actm) = func.as_assoc_item(db) {
-            if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
-                item.trait_name(trt.name(db).to_smol_str());
-            }
-        }
-    }
-
-    if let Some(import_to_add) = import_to_add {
-        item.add_import(import_to_add);
-    }
-    item.lookup_by(name.to_smol_str());
 
     let ret_type = func.ret_type(db);
     item.set_relevance(CompletionRelevance {
@@ -100,6 +82,24 @@ fn render(
         }
     }
 
+    item.set_documentation(ctx.docs(func))
+        .set_deprecated(ctx.is_deprecated(func) || ctx.is_deprecated_assoc_item(func))
+        .detail(detail(db, func))
+        .add_call_parens(completion, call, params);
+
+    if import_to_add.is_none() {
+        if let Some(actm) = func.as_assoc_item(db) {
+            if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
+                item.trait_name(trt.name(db).to_smol_str());
+            }
+        }
+    }
+
+    if let Some(import_to_add) = import_to_add {
+        item.add_import(import_to_add);
+    }
+    item.lookup_by(name.to_smol_str());
+
     item.build()
 }
 
index be1d3212810f05e8f465da31d352789101ff3a1e..5bfb4349edcecae0d8453c671bc10d3c03a65045 100644 (file)
@@ -2,6 +2,7 @@
 
 use hir::{AsAssocItem, HirDisplay};
 use ide_db::SymbolKind;
+use syntax::SmolStr;
 
 use crate::{item::CompletionItem, render::RenderContext};
 
@@ -28,11 +29,10 @@ fn render(
 ) -> Option<CompletionItem> {
     let db = ctx.db();
 
-    // FIXME: smolstr?
     let name = if with_eq {
-        format!("{} = ", type_alias.name(db))
+        SmolStr::from_iter([&*type_alias.name(db).to_smol_str(), " = "])
     } else {
-        type_alias.name(db).to_string()
+        type_alias.name(db).to_smol_str()
     };
     let detail = type_alias.display(db).to_string();