Stop using an Arc when setting the file text

This commit is contained in:
Laurențiu Nicola 2024-01-10 12:17:10 +02:00
parent 02b6c181dd
commit 0f43b55e83
11 changed files with 21 additions and 24 deletions

View file

@ -13,7 +13,7 @@ use crate::{CrateGraph, SourceDatabaseExt, SourceDatabaseExt2, SourceRoot, Sourc
#[derive(Default)]
pub struct FileChange {
pub roots: Option<Vec<SourceRoot>>,
pub files_changed: Vec<(FileId, Option<Arc<str>>)>,
pub files_changed: Vec<(FileId, Option<String>)>,
pub crate_graph: Option<CrateGraph>,
}
@ -42,7 +42,7 @@ impl FileChange {
self.roots = Some(roots);
}
pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<str>>) {
pub fn change_file(&mut self, file_id: FileId, new_text: Option<String>) {
self.files_changed.push((file_id, new_text))
}
@ -68,7 +68,7 @@ impl FileChange {
let source_root = db.source_root(source_root_id);
let durability = durability(&source_root);
// XXX: can't actually remove the file, just reset the text
let text = text.unwrap_or_else(|| Arc::from(""));
let text = text.as_ref().map(String::as_str).unwrap_or_else(|| "");
db.set_file_text_with_durability(file_id, text, durability)
}
if let Some(crate_graph) = self.crate_graph {

View file

@ -115,14 +115,14 @@ fn file_text(db: &dyn SourceDatabaseExt, file_id: FileId) -> Arc<str> {
}
pub trait SourceDatabaseExt2 {
fn set_file_text(&mut self, file_id: FileId, text: Arc<str>) {
fn set_file_text(&mut self, file_id: FileId, text: &str) {
self.set_file_text_with_durability(file_id, text, Durability::LOW);
}
fn set_file_text_with_durability(
&mut self,
file_id: FileId,
text: Arc<str>,
text: &str,
durability: Durability,
);
}
@ -131,7 +131,7 @@ impl<Db: ?Sized + SourceDatabaseExt> SourceDatabaseExt2 for Db {
fn set_file_text_with_durability(
&mut self,
file_id: FileId,
text: Arc<str>,
text: &str,
durability: Durability,
) {
let bytes = text.as_bytes();

View file

@ -1,6 +1,5 @@
use base_db::{SourceDatabase, SourceDatabaseExt2 as _};
use test_fixture::WithFixture;
use triomphe::Arc;
use crate::{db::DefDatabase, nameres::tests::TestDB, AdtId, ModuleDefId};
@ -17,7 +16,7 @@ fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change:
});
assert!(format!("{events:?}").contains("crate_def_map"), "{events:#?}")
}
db.set_file_text(pos.file_id, Arc::from(ra_fixture_change));
db.set_file_text(pos.file_id, ra_fixture_change);
{
let events = db.log_executed(|| {
@ -267,7 +266,7 @@ fn quux() { 92 }
m!(Y);
m!(Z);
"#;
db.set_file_text(pos.file_id, Arc::from(new_text));
db.set_file_text(pos.file_id, new_text);
{
let events = db.log_executed(|| {

View file

@ -48,7 +48,7 @@ impl ChangeWithProcMacros {
}
}
pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<str>>) {
pub fn change_file(&mut self, file_id: FileId, new_text: Option<String>) {
self.source_change.change_file(file_id, new_text)
}

View file

@ -575,7 +575,7 @@ fn salsa_bug() {
}
";
db.set_file_text(pos.file_id, Arc::from(new_text));
db.set_file_text(pos.file_id, new_text);
let module = db.module_for_file(pos.file_id);
let crate_def_map = module.def_map(&db);

View file

@ -1,6 +1,5 @@
use base_db::SourceDatabaseExt2 as _;
use test_fixture::WithFixture;
use triomphe::Arc;
use crate::{db::HirDatabase, test_db::TestDB};
@ -33,7 +32,7 @@ fn foo() -> i32 {
1
}";
db.set_file_text(pos.file_id, Arc::from(new_text));
db.set_file_text(pos.file_id, new_text);
{
let events = db.log_executed(|| {
@ -85,7 +84,7 @@ fn baz() -> i32 {
}
";
db.set_file_text(pos.file_id, Arc::from(new_text));
db.set_file_text(pos.file_id, new_text);
{
let events = db.log_executed(|| {

View file

@ -259,7 +259,7 @@ impl Analysis {
false,
CrateOrigin::Local { repo: None, name: None },
);
change.change_file(file_id, Some(Arc::from(text)));
change.change_file(file_id, Some(text));
change.set_crate_graph(crate_graph);
change.set_target_data_layouts(vec![Err("fixture has no layout".into())]);
change.set_toolchains(vec![None]);

View file

@ -361,8 +361,8 @@ fn load_crate_graph(
let changes = vfs.take_changes();
for file in changes {
if let vfs::Change::Create(v) | vfs::Change::Modify(v) = file.change {
if let Ok(text) = std::str::from_utf8(&v) {
analysis_change.change_file(file.file_id, Some(text.into()))
if let Ok(text) = String::from_utf8(v) {
analysis_change.change_file(file.file_id, Some(text))
}
}
}

View file

@ -134,7 +134,7 @@ impl Tester {
let should_have_no_error = text.contains("// check-pass")
|| text.contains("// build-pass")
|| text.contains("// run-pass");
change.change_file(self.root_file, Some(Arc::from(text)));
change.change_file(self.root_file, Some(text));
self.host.apply_change(change);
let diagnostic_config = DiagnosticsConfig::test_sample();

View file

@ -330,7 +330,7 @@ impl GlobalState {
// FIXME: Consider doing normalization in the `vfs` instead? That allows
// getting rid of some locking
let (text, line_endings) = LineEndings::normalize(text);
(Arc::from(text), line_endings)
(text, line_endings)
})
} else {
None

View file

@ -20,7 +20,6 @@ use ide_db::{
};
use project_model::CargoConfig;
use test_utils::project_root;
use triomphe::Arc;
use vfs::{AbsPathBuf, VfsPath};
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
@ -70,7 +69,7 @@ fn integrated_highlighting_benchmark() {
let mut text = host.analysis().file_text(file_id).unwrap().to_string();
text.push_str("\npub fn _dummy() {}\n");
let mut change = ChangeWithProcMacros::new();
change.change_file(file_id, Some(Arc::from(text)));
change.change_file(file_id, Some(text));
host.apply_change(change);
}
@ -125,7 +124,7 @@ fn integrated_completion_benchmark() {
patch(&mut text, "db.struct_data(self.id)", "sel;\ndb.struct_data(self.id)")
+ "sel".len();
let mut change = ChangeWithProcMacros::new();
change.change_file(file_id, Some(Arc::from(text)));
change.change_file(file_id, Some(text));
host.apply_change(change);
completion_offset
};
@ -168,7 +167,7 @@ fn integrated_completion_benchmark() {
patch(&mut text, "sel;\ndb.struct_data(self.id)", ";sel;\ndb.struct_data(self.id)")
+ ";sel".len();
let mut change = ChangeWithProcMacros::new();
change.change_file(file_id, Some(Arc::from(text)));
change.change_file(file_id, Some(text));
host.apply_change(change);
completion_offset
};
@ -210,7 +209,7 @@ fn integrated_completion_benchmark() {
patch(&mut text, "sel;\ndb.struct_data(self.id)", "self.;\ndb.struct_data(self.id)")
+ "self.".len();
let mut change = ChangeWithProcMacros::new();
change.change_file(file_id, Some(Arc::from(text)));
change.change_file(file_id, Some(text));
host.apply_change(change);
completion_offset
};