Skip to content

Commit 0b50d80

Browse files
committed
scip: minor clean-ups
Avoids a couple redundant hash map lookups and so.
1 parent 8ee23f4 commit 0b50d80

File tree

1 file changed

+8
-16
lines changed
  • crates/rust-analyzer/src/cli

1 file changed

+8
-16
lines changed

crates/rust-analyzer/src/cli/scip.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,20 @@ impl flags::Scip {
107107

108108
let mut occurrence = scip_types::Occurrence::default();
109109
occurrence.range = text_range_to_scip_range(&line_index, range);
110-
occurrence.symbol = match tokens_to_symbol.get(&id) {
111-
Some(symbol) => symbol.clone(),
112-
None => {
113-
let symbol = match &token.moniker {
114-
Some(moniker) => moniker_to_symbol(&moniker),
115-
None => new_local_symbol(),
116-
};
117-
118-
let symbol = scip::symbol::format_symbol(symbol);
119-
tokens_to_symbol.insert(id, symbol.clone());
120-
symbol
121-
}
122-
};
110+
occurrence.symbol = tokens_to_symbol.entry(id).or_insert_with(|| {
111+
let symbol = match &token.moniker {
112+
Some(moniker) => moniker_to_symbol(&moniker),
113+
None => new_local_symbol(),
114+
};
115+
scip::symbol::format_symbol(symbol)
116+
}).clone();
123117

124118
if let Some(def) = token.definition {
125119
if def.range == range {
126120
occurrence.symbol_roles |= scip_types::SymbolRole::Definition as i32;
127121
}
128122

129-
if !symbols_emitted.contains(&id) {
130-
symbols_emitted.insert(id);
131-
123+
if symbols_emitted.insert(id) {
132124
let mut symbol_info = scip_types::SymbolInformation::default();
133125
symbol_info.symbol = occurrence.symbol.clone();
134126
if let Some(hover) = &token.hover {

0 commit comments

Comments
 (0)