Skip to content

Commit 60dfe8c

Browse files
committed
Replace a few String instances with SmolStr in completions
1 parent 7f7a364 commit 60dfe8c

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

crates/ide_completion/src/render/builder_ext.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Extensions for `Builder` structure required for item rendering.
22
33
use itertools::Itertools;
4+
use syntax::SmolStr;
45

56
use crate::{context::PathKind, item::Builder, patterns::ImmediateLocation, CompletionContext};
67

@@ -56,7 +57,7 @@ impl Builder {
5657
pub(super) fn add_call_parens(
5758
&mut self,
5859
ctx: &CompletionContext,
59-
name: String,
60+
name: SmolStr,
6061
params: Params,
6162
) -> &mut Builder {
6263
if !self.should_add_parens(ctx) {

crates/ide_completion/src/render/enum_variant.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::iter;
55
use hir::{db::HirDatabase, HasAttrs, HirDisplay, StructKind};
66
use ide_db::SymbolKind;
77
use itertools::Itertools;
8+
use syntax::SmolStr;
89

910
use crate::{
1011
item::{CompletionItem, ImportEdit},
@@ -48,10 +49,10 @@ fn render(
4849
false,
4950
),
5051
};
52+
let qualified_name = qualified_name.to_string();
53+
let short_qualified_name: SmolStr = short_qualified_name.to_string().into();
5154

52-
// FIXME: ModPath::to_smol_str()?
53-
let mut item =
54-
CompletionItem::new(SymbolKind::Variant, ctx.source_range(), qualified_name.to_string());
55+
let mut item = CompletionItem::new(SymbolKind::Variant, ctx.source_range(), qualified_name);
5556
item.set_documentation(variant.docs(db))
5657
.set_deprecated(ctx.is_deprecated(variant))
5758
.detail(detail(db, variant, variant_kind));
@@ -60,8 +61,6 @@ fn render(
6061
item.add_import(import_to_add);
6162
}
6263

63-
// FIXME: ModPath::to_smol_str()?
64-
let short_qualified_name = short_qualified_name.to_string();
6564
if variant_kind == hir::StructKind::Tuple {
6665
cov_mark::hit!(inserts_parens_for_tuple_enums);
6766
let params = Params::Anonymous(variant.fields(db).len());

crates/ide_completion/src/render/function.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ fn render(
5252
let name = local_name.unwrap_or_else(|| func.name(db));
5353
let params = params(completion, func, &func_type);
5454

55-
// FIXME: SmolStr?
5655
let call = match &func_type {
57-
FuncType::Method(Some(receiver)) => format!("{}.{}", receiver, &name),
58-
_ => name.to_string(),
56+
FuncType::Method(Some(receiver)) => format!("{}.{}", receiver, &name).into(),
57+
_ => name.to_smol_str(),
5958
};
6059
let mut item = CompletionItem::new(
6160
if func.self_param(db).is_some() {
@@ -66,23 +65,6 @@ fn render(
6665
ctx.source_range(),
6766
call.clone(),
6867
);
69-
item.set_documentation(ctx.docs(func))
70-
.set_deprecated(ctx.is_deprecated(func) || ctx.is_deprecated_assoc_item(func))
71-
.detail(detail(db, func))
72-
.add_call_parens(completion, call.clone(), params);
73-
74-
if import_to_add.is_none() {
75-
if let Some(actm) = func.as_assoc_item(db) {
76-
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
77-
item.trait_name(trt.name(db).to_smol_str());
78-
}
79-
}
80-
}
81-
82-
if let Some(import_to_add) = import_to_add {
83-
item.add_import(import_to_add);
84-
}
85-
item.lookup_by(name.to_smol_str());
8668

8769
let ret_type = func.ret_type(db);
8870
item.set_relevance(CompletionRelevance {
@@ -100,6 +82,24 @@ fn render(
10082
}
10183
}
10284

85+
item.set_documentation(ctx.docs(func))
86+
.set_deprecated(ctx.is_deprecated(func) || ctx.is_deprecated_assoc_item(func))
87+
.detail(detail(db, func))
88+
.add_call_parens(completion, call, params);
89+
90+
if import_to_add.is_none() {
91+
if let Some(actm) = func.as_assoc_item(db) {
92+
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
93+
item.trait_name(trt.name(db).to_smol_str());
94+
}
95+
}
96+
}
97+
98+
if let Some(import_to_add) = import_to_add {
99+
item.add_import(import_to_add);
100+
}
101+
item.lookup_by(name.to_smol_str());
102+
103103
item.build()
104104
}
105105

crates/ide_completion/src/render/type_alias.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use hir::{AsAssocItem, HirDisplay};
44
use ide_db::SymbolKind;
5+
use syntax::SmolStr;
56

67
use crate::{item::CompletionItem, render::RenderContext};
78

@@ -28,11 +29,10 @@ fn render(
2829
) -> Option<CompletionItem> {
2930
let db = ctx.db();
3031

31-
// FIXME: smolstr?
3232
let name = if with_eq {
33-
format!("{} = ", type_alias.name(db))
33+
SmolStr::from_iter([&*type_alias.name(db).to_smol_str(), " = "])
3434
} else {
35-
type_alias.name(db).to_string()
35+
type_alias.name(db).to_smol_str()
3636
};
3737
let detail = type_alias.display(db).to_string();
3838

0 commit comments

Comments
 (0)