Skip to content

Commit c8a5e43

Browse files
committed
chore: Remove unnecessary Arc clones
1 parent cdcadb4 commit c8a5e43

File tree

3 files changed

+16
-40
lines changed

3 files changed

+16
-40
lines changed

Diff for: crates/base-db/src/lib.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ impl Files {
6464
}
6565

6666
pub fn set_file_text(&self, db: &mut dyn SourceDatabase, file_id: vfs::FileId, text: &str) {
67-
let files = Arc::clone(&self.files);
68-
match files.entry(file_id) {
67+
match self.files.entry(file_id) {
6968
Entry::Occupied(mut occupied) => {
7069
occupied.get_mut().set_text(db).to(Arc::from(text));
7170
}
@@ -83,8 +82,7 @@ impl Files {
8382
text: &str,
8483
durability: Durability,
8584
) {
86-
let files = Arc::clone(&self.files);
87-
match files.entry(file_id) {
85+
match self.files.entry(file_id) {
8886
Entry::Occupied(mut occupied) => {
8987
occupied.get_mut().set_text(db).with_durability(durability).to(Arc::from(text));
9088
}
@@ -113,8 +111,7 @@ impl Files {
113111
source_root: Arc<SourceRoot>,
114112
durability: Durability,
115113
) {
116-
let source_roots = Arc::clone(&self.source_roots);
117-
match source_roots.entry(source_root_id) {
114+
match self.source_roots.entry(source_root_id) {
118115
Entry::Occupied(mut occupied) => {
119116
occupied.get_mut().set_source_root(db).with_durability(durability).to(source_root);
120117
}
@@ -141,9 +138,7 @@ impl Files {
141138
source_root_id: SourceRootId,
142139
durability: Durability,
143140
) {
144-
let file_source_roots = Arc::clone(&self.file_source_roots);
145-
// let db = self;
146-
match file_source_roots.entry(id) {
141+
match self.file_source_roots.entry(id) {
147142
Entry::Occupied(mut occupied) => {
148143
occupied
149144
.get_mut()
@@ -203,7 +198,8 @@ pub trait RootQueryDb: SourceDatabase + salsa::Database {
203198
fn parse(&self, file_id: EditionedFileId) -> Parse<ast::SourceFile>;
204199

205200
/// Returns the set of errors obtained from parsing the file including validation errors.
206-
fn parse_errors(&self, file_id: EditionedFileId) -> Option<Arc<[SyntaxError]>>;
201+
#[salsa::transparent]
202+
fn parse_errors(&self, file_id: EditionedFileId) -> Option<&[SyntaxError]>;
207203

208204
#[salsa::transparent]
209205
fn toolchain_channel(&self, krate: Crate) -> Option<ReleaseChannel>;
@@ -318,12 +314,16 @@ fn parse(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Parse<ast::SourceFil
318314
ast::SourceFile::parse(&text, edition)
319315
}
320316

321-
fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<Arc<[SyntaxError]>> {
322-
let errors = db.parse(file_id).errors();
323-
match &*errors {
324-
[] => None,
325-
[..] => Some(errors.into()),
317+
fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<&[SyntaxError]> {
318+
#[salsa::tracked(return_ref)]
319+
fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<Box<[SyntaxError]>> {
320+
let errors = db.parse(file_id).errors();
321+
match &*errors {
322+
[] => None,
323+
[..] => Some(errors.into()),
324+
}
326325
}
326+
parse_errors(db, file_id).as_ref().map(|it| &**it)
327327
}
328328

329329
fn source_root_crates(db: &dyn RootQueryDb, id: SourceRootId) -> Arc<[Crate]> {

Diff for: crates/ide-diagnostics/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ pub fn syntax_diagnostics(
332332

333333
// [#3434] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
334334
db.parse_errors(editioned_file_id_wrapper)
335-
.as_deref()
336335
.into_iter()
337336
.flatten()
338337
.take(128)
@@ -409,8 +408,7 @@ pub fn semantic_diagnostics(
409408
// A bunch of parse errors in a file indicate some bigger structural parse changes in the
410409
// file, so we skip semantic diagnostics so we can show these faster.
411410
Some(m) => {
412-
if db.parse_errors(editioned_file_id_wrapper).as_deref().is_none_or(|es| es.len() < 16)
413-
{
411+
if db.parse_errors(editioned_file_id_wrapper).is_none_or(|es| es.len() < 16) {
414412
m.diagnostics(db, &mut diags, config.style_lints);
415413
}
416414
}

Diff for: crates/ide/src/inlay_hints/bind_pat.rs

-22
Original file line numberDiff line numberDiff line change
@@ -855,28 +855,6 @@ fn main() {
855855
//^ |i32| -> ()
856856
let p = (y, z);
857857
//^ (|i32| -> i32, |i32| -> ())
858-
}
859-
"#,
860-
);
861-
check_with_config(
862-
InlayHintsConfig {
863-
type_hints: true,
864-
closure_style: ClosureStyle::ClosureWithId,
865-
..DISABLED_CONFIG
866-
},
867-
r#"
868-
//- minicore: fn
869-
fn main() {
870-
let x = || 2;
871-
//^ {closure#25600}
872-
let y = |t: i32| x() + t;
873-
//^ {closure#25601}
874-
let mut t = 5;
875-
//^ i32
876-
let z = |k: i32| { t += k; };
877-
//^ {closure#25602}
878-
let p = (y, z);
879-
//^ ({closure#25601}, {closure#25602})
880858
}
881859
"#,
882860
);

0 commit comments

Comments
 (0)