diff options
| author | roife <roifewu@gmail.com> | 2024-01-02 21:33:06 +0800 |
|---|---|---|
| committer | roife <roifewu@gmail.com> | 2024-01-02 21:33:06 +0800 |
| commit | 919ecc6c3232cad9dc8e3f6ea03082415c6609fb (patch) | |
| tree | 14b8c1a641a8c20807d3e20025e6248c360fd5c1 | |
| parent | bc1a5774fd9fc1cbc2ffcb74d72e2894e2171d0b (diff) | |
| download | rust-919ecc6c3232cad9dc8e3f6ea03082415c6609fb.tar.gz rust-919ecc6c3232cad9dc8e3f6ea03082415c6609fb.zip | |
Use HashSet to enhance performance in for_unique_generic_name in suggest_name
| -rw-r--r-- | crates/ide-assists/src/utils/suggest_name.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/crates/ide-assists/src/utils/suggest_name.rs b/crates/ide-assists/src/utils/suggest_name.rs index 455bbc0b681..b4c6cbff2a4 100644 --- a/crates/ide-assists/src/utils/suggest_name.rs +++ b/crates/ide-assists/src/utils/suggest_name.rs @@ -1,5 +1,7 @@ //! This module contains functions to suggest names for expressions, functions and other items +use std::collections::HashSet; + use hir::Semantics; use ide_db::RootDatabase; use itertools::Itertools; @@ -76,12 +78,9 @@ pub(crate) fn for_unique_generic_name( ast::GenericParam::TypeParam(t) => t.name().unwrap().to_string(), p => p.to_string(), }) - .collect_vec(); + .collect::<HashSet<_>>(); let mut name = name.to_string(); 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; while param_names.contains(&name) { name.truncate(base_len); |
