Use HashSet to enhance performance in for_unique_generic_name in suggest_name
This commit is contained in:
parent
bc1a5774fd
commit
919ecc6c32
1 changed files with 3 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
||||||
//! This module contains functions to suggest names for expressions, functions and other items
|
//! This module contains functions to suggest names for expressions, functions and other items
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use hir::Semantics;
|
use hir::Semantics;
|
||||||
use ide_db::RootDatabase;
|
use ide_db::RootDatabase;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -76,12 +78,9 @@ pub(crate) fn for_unique_generic_name(
|
||||||
ast::GenericParam::TypeParam(t) => t.name().unwrap().to_string(),
|
ast::GenericParam::TypeParam(t) => t.name().unwrap().to_string(),
|
||||||
p => p.to_string(),
|
p => p.to_string(),
|
||||||
})
|
})
|
||||||
.collect_vec();
|
.collect::<HashSet<_>>();
|
||||||
let mut name = name.to_string();
|
let mut name = name.to_string();
|
||||||
let base_len = name.len();
|
let base_len = name.len();
|
||||||
// 4*len bytes for base, and 2 bytes for 2 digits
|
|
||||||
name.reserve(4 * base_len + 2);
|
|
||||||
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
while param_names.contains(&name) {
|
while param_names.contains(&name) {
|
||||||
name.truncate(base_len);
|
name.truncate(base_len);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue