Skip to content

Commit 0f43b55

Browse files
committed
Stop using an Arc when setting the file text
1 parent 02b6c18 commit 0f43b55

File tree

11 files changed

+21
-24
lines changed

11 files changed

+21
-24
lines changed

crates/base-db/src/change.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{CrateGraph, SourceDatabaseExt, SourceDatabaseExt2, SourceRoot, Sourc
1313
#[derive(Default)]
1414
pub struct FileChange {
1515
pub roots: Option<Vec<SourceRoot>>,
16-
pub files_changed: Vec<(FileId, Option<Arc<str>>)>,
16+
pub files_changed: Vec<(FileId, Option<String>)>,
1717
pub crate_graph: Option<CrateGraph>,
1818
}
1919

@@ -42,7 +42,7 @@ impl FileChange {
4242
self.roots = Some(roots);
4343
}
4444

45-
pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<str>>) {
45+
pub fn change_file(&mut self, file_id: FileId, new_text: Option<String>) {
4646
self.files_changed.push((file_id, new_text))
4747
}
4848

@@ -68,7 +68,7 @@ impl FileChange {
6868
let source_root = db.source_root(source_root_id);
6969
let durability = durability(&source_root);
7070
// XXX: can't actually remove the file, just reset the text
71-
let text = text.unwrap_or_else(|| Arc::from(""));
71+
let text = text.as_ref().map(String::as_str).unwrap_or_else(|| "");
7272
db.set_file_text_with_durability(file_id, text, durability)
7373
}
7474
if let Some(crate_graph) = self.crate_graph {

crates/base-db/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ fn file_text(db: &dyn SourceDatabaseExt, file_id: FileId) -> Arc<str> {
115115
}
116116

117117
pub trait SourceDatabaseExt2 {
118-
fn set_file_text(&mut self, file_id: FileId, text: Arc<str>) {
118+
fn set_file_text(&mut self, file_id: FileId, text: &str) {
119119
self.set_file_text_with_durability(file_id, text, Durability::LOW);
120120
}
121121

122122
fn set_file_text_with_durability(
123123
&mut self,
124124
file_id: FileId,
125-
text: Arc<str>,
125+
text: &str,
126126
durability: Durability,
127127
);
128128
}
@@ -131,7 +131,7 @@ impl<Db: ?Sized + SourceDatabaseExt> SourceDatabaseExt2 for Db {
131131
fn set_file_text_with_durability(
132132
&mut self,
133133
file_id: FileId,
134-
text: Arc<str>,
134+
text: &str,
135135
durability: Durability,
136136
) {
137137
let bytes = text.as_bytes();

crates/hir-def/src/nameres/tests/incremental.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use base_db::{SourceDatabase, SourceDatabaseExt2 as _};
22
use test_fixture::WithFixture;
3-
use triomphe::Arc;
43

54
use crate::{db::DefDatabase, nameres::tests::TestDB, AdtId, ModuleDefId};
65

@@ -17,7 +16,7 @@ fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change:
1716
});
1817
assert!(format!("{events:?}").contains("crate_def_map"), "{events:#?}")
1918
}
20-
db.set_file_text(pos.file_id, Arc::from(ra_fixture_change));
19+
db.set_file_text(pos.file_id, ra_fixture_change);
2120

2221
{
2322
let events = db.log_executed(|| {
@@ -267,7 +266,7 @@ fn quux() { 92 }
267266
m!(Y);
268267
m!(Z);
269268
"#;
270-
db.set_file_text(pos.file_id, Arc::from(new_text));
269+
db.set_file_text(pos.file_id, new_text);
271270

272271
{
273272
let events = db.log_executed(|| {

crates/hir-expand/src/change.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl ChangeWithProcMacros {
4848
}
4949
}
5050

51-
pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<str>>) {
51+
pub fn change_file(&mut self, file_id: FileId, new_text: Option<String>) {
5252
self.source_change.change_file(file_id, new_text)
5353
}
5454

crates/hir-ty/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ fn salsa_bug() {
575575
}
576576
";
577577

578-
db.set_file_text(pos.file_id, Arc::from(new_text));
578+
db.set_file_text(pos.file_id, new_text);
579579

580580
let module = db.module_for_file(pos.file_id);
581581
let crate_def_map = module.def_map(&db);

crates/hir-ty/src/tests/incremental.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use base_db::SourceDatabaseExt2 as _;
22
use test_fixture::WithFixture;
3-
use triomphe::Arc;
43

54
use crate::{db::HirDatabase, test_db::TestDB};
65

@@ -33,7 +32,7 @@ fn foo() -> i32 {
3332
1
3433
}";
3534

36-
db.set_file_text(pos.file_id, Arc::from(new_text));
35+
db.set_file_text(pos.file_id, new_text);
3736

3837
{
3938
let events = db.log_executed(|| {
@@ -85,7 +84,7 @@ fn baz() -> i32 {
8584
}
8685
";
8786

88-
db.set_file_text(pos.file_id, Arc::from(new_text));
87+
db.set_file_text(pos.file_id, new_text);
8988

9089
{
9190
let events = db.log_executed(|| {

crates/ide/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl Analysis {
259259
false,
260260
CrateOrigin::Local { repo: None, name: None },
261261
);
262-
change.change_file(file_id, Some(Arc::from(text)));
262+
change.change_file(file_id, Some(text));
263263
change.set_crate_graph(crate_graph);
264264
change.set_target_data_layouts(vec![Err("fixture has no layout".into())]);
265265
change.set_toolchains(vec![None]);

crates/load-cargo/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ fn load_crate_graph(
361361
let changes = vfs.take_changes();
362362
for file in changes {
363363
if let vfs::Change::Create(v) | vfs::Change::Modify(v) = file.change {
364-
if let Ok(text) = std::str::from_utf8(&v) {
365-
analysis_change.change_file(file.file_id, Some(text.into()))
364+
if let Ok(text) = String::from_utf8(v) {
365+
analysis_change.change_file(file.file_id, Some(text))
366366
}
367367
}
368368
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl Tester {
134134
let should_have_no_error = text.contains("// check-pass")
135135
|| text.contains("// build-pass")
136136
|| text.contains("// run-pass");
137-
change.change_file(self.root_file, Some(Arc::from(text)));
137+
change.change_file(self.root_file, Some(text));
138138
self.host.apply_change(change);
139139
let diagnostic_config = DiagnosticsConfig::test_sample();
140140

crates/rust-analyzer/src/global_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl GlobalState {
330330
// FIXME: Consider doing normalization in the `vfs` instead? That allows
331331
// getting rid of some locking
332332
let (text, line_endings) = LineEndings::normalize(text);
333-
(Arc::from(text), line_endings)
333+
(text, line_endings)
334334
})
335335
} else {
336336
None

0 commit comments

Comments
 (0)