Skip to content

Commit c151e13

Browse files
committed
optimize code
1 parent 871d948 commit c151e13

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

crates/code_analysis/src/compilation/analyzer/decl/exprs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use emmylua_parser::{
22
LuaAstNode, LuaAstToken, LuaClosureExpr, LuaIndexExpr, LuaIndexKey, LuaLiteralExpr,
33
LuaLiteralToken, LuaNameExpr, LuaTableExpr,
44
};
5-
use internment::ArcIntern;
65

76
use crate::{
87
db_index::{LuaDecl, LuaMember, LuaMemberKey, LuaMemberOwner},
@@ -175,7 +174,7 @@ pub fn analyze_literal_expr(analyzer: &mut DeclAnalyzer, expr: LuaLiteralExpr) -
175174

176175
analyzer.db.get_reference_index_mut().add_string_reference(
177176
file_id,
178-
ArcIntern::new(value),
177+
&value,
179178
string_token.get_range(),
180179
);
181180
}

crates/code_analysis/src/db_index/reference/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod string_reference;
44
use std::collections::{HashMap, HashSet};
55

66
use emmylua_parser::{LuaSyntaxId, LuaSyntaxKind};
7-
use internment::ArcIntern;
87
use local_reference::LocalReference;
98
use rowan::TextRange;
109
use smol_str::SmolStr;
@@ -61,12 +60,7 @@ impl LuaReferenceIndex {
6160
.insert(syntax_id);
6261
}
6362

64-
pub fn add_string_reference(
65-
&mut self,
66-
file_id: FileId,
67-
string: ArcIntern<String>,
68-
range: TextRange,
69-
) {
63+
pub fn add_string_reference(&mut self, file_id: FileId, string: &str, range: TextRange) {
7064
self.string_references
7165
.entry(file_id)
7266
.or_insert_with(StringReference::new)
@@ -169,13 +163,12 @@ impl LuaReferenceIndex {
169163
}
170164

171165
pub fn get_string_references(&self, string_value: &str) -> Vec<InFiled<TextRange>> {
172-
let arc_string = ArcIntern::new(string_value.to_string());
173166
let results = self
174167
.string_references
175168
.iter()
176169
.map(|(file_id, string_reference)| {
177170
string_reference
178-
.get_string_references(&arc_string)
171+
.get_string_references(&string_value)
179172
.into_iter()
180173
.map(|range| InFiled::new(*file_id, range))
181174
})

crates/code_analysis/src/db_index/reference/string_reference.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use internment::ArcIntern;
21
use rowan::TextRange;
2+
use smol_str::SmolStr;
33
use std::collections::HashMap;
44

55
#[derive(Debug)]
66
pub struct StringReference {
7-
string_references: HashMap<ArcIntern<String>, Vec<TextRange>>,
7+
string_references: HashMap<SmolStr, Vec<TextRange>>,
88
}
99

1010
impl StringReference {
@@ -14,14 +14,14 @@ impl StringReference {
1414
}
1515
}
1616

17-
pub fn add_string_reference(&mut self, string: ArcIntern<String>, range: TextRange) {
17+
pub fn add_string_reference(&mut self, string: &str, range: TextRange) {
1818
self.string_references
19-
.entry(string)
19+
.entry(SmolStr::new(string))
2020
.or_insert_with(Vec::new)
2121
.push(range);
2222
}
2323

24-
pub fn get_string_references(&self, string: &ArcIntern<String>) -> Vec<TextRange> {
24+
pub fn get_string_references(&self, string: &str) -> Vec<TextRange> {
2525
self.string_references
2626
.get(string)
2727
.cloned()

0 commit comments

Comments
 (0)