Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/base-db/src/change.rs6
-rw-r--r--crates/base-db/src/fixture.rs6
-rw-r--r--crates/base-db/src/lib.rs6
-rw-r--r--crates/hir-def/src/nameres/tests/incremental.rs6
-rw-r--r--crates/hir-def/src/test_db.rs2
-rw-r--r--crates/hir-ty/src/test_db.rs2
-rw-r--r--crates/hir-ty/src/tests.rs5
-rw-r--r--crates/hir-ty/src/tests/incremental.rs5
-rw-r--r--crates/ide-db/src/lib.rs2
-rw-r--r--crates/ide-db/src/search.rs6
-rw-r--r--crates/ide-ssr/src/lib.rs2
-rw-r--r--crates/ide/src/lib.rs4
-rw-r--r--crates/ide/src/status.rs4
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs6
-rw-r--r--crates/rust-analyzer/src/global_state.rs2
-rw-r--r--crates/rust-analyzer/src/integrated_benchmarks.rs6
16 files changed, 34 insertions, 36 deletions
diff --git a/crates/base-db/src/change.rs b/crates/base-db/src/change.rs
index b906511dbc..fe3792ef6c 100644
--- a/crates/base-db/src/change.rs
+++ b/crates/base-db/src/change.rs
@@ -12,7 +12,7 @@ use crate::{CrateGraph, ProcMacros, SourceDatabaseExt, SourceRoot, SourceRootId}
#[derive(Default)]
pub struct Change {
pub roots: Option<Vec<SourceRoot>>,
- pub files_changed: Vec<(FileId, Option<Arc<String>>)>,
+ pub files_changed: Vec<(FileId, Option<Arc<str>>)>,
pub crate_graph: Option<CrateGraph>,
pub proc_macros: Option<ProcMacros>,
}
@@ -42,7 +42,7 @@ impl Change {
self.roots = Some(roots);
}
- pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<String>>) {
+ pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<str>>) {
self.files_changed.push((file_id, new_text))
}
@@ -72,7 +72,7 @@ impl Change {
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_default();
+ let text = text.unwrap_or_else(|| Arc::from(""));
db.set_file_text_with_durability(file_id, text, durability)
}
if let Some(crate_graph) = self.crate_graph {
diff --git a/crates/base-db/src/fixture.rs b/crates/base-db/src/fixture.rs
index f01f75b138..1936eabdd9 100644
--- a/crates/base-db/src/fixture.rs
+++ b/crates/base-db/src/fixture.rs
@@ -190,7 +190,7 @@ impl ChangeFixture {
default_target_data_layout = meta.target_data_layout;
}
- change.change_file(file_id, Some(Arc::new(text)));
+ change.change_file(file_id, Some(Arc::from(text)));
let path = VfsPath::new_virtual_path(meta.path);
file_set.insert(file_id, path);
files.push(file_id);
@@ -240,7 +240,7 @@ impl ChangeFixture {
fs.insert(core_file, VfsPath::new_virtual_path("/sysroot/core/lib.rs".to_string()));
roots.push(SourceRoot::new_library(fs));
- change.change_file(core_file, Some(Arc::new(mini_core.source_code())));
+ change.change_file(core_file, Some(Arc::from(mini_core.source_code())));
let all_crates = crate_graph.crates_in_topological_order();
@@ -279,7 +279,7 @@ impl ChangeFixture {
);
roots.push(SourceRoot::new_library(fs));
- change.change_file(proc_lib_file, Some(Arc::new(source)));
+ change.change_file(proc_lib_file, Some(Arc::from(source)));
let all_crates = crate_graph.crates_in_topological_order();
diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs
index faddf19e34..358ca1453d 100644
--- a/crates/base-db/src/lib.rs
+++ b/crates/base-db/src/lib.rs
@@ -57,7 +57,7 @@ pub const DEFAULT_LRU_CAP: usize = 128;
pub trait FileLoader {
/// Text of the file.
- fn file_text(&self, file_id: FileId) -> Arc<String>;
+ fn file_text(&self, file_id: FileId) -> Arc<str>;
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId>;
fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>>;
}
@@ -90,7 +90,7 @@ fn parse_query(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFil
#[salsa::query_group(SourceDatabaseExtStorage)]
pub trait SourceDatabaseExt: SourceDatabase {
#[salsa::input]
- fn file_text(&self, file_id: FileId) -> Arc<String>;
+ fn file_text(&self, file_id: FileId) -> Arc<str>;
/// Path to a file, relative to the root of its source root.
/// Source root of the file.
#[salsa::input]
@@ -118,7 +118,7 @@ fn source_root_crates(db: &dyn SourceDatabaseExt, id: SourceRootId) -> Arc<FxHas
pub struct FileLoaderDelegate<T>(pub T);
impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> {
- fn file_text(&self, file_id: FileId) -> Arc<String> {
+ fn file_text(&self, file_id: FileId) -> Arc<str> {
SourceDatabaseExt::file_text(self.0, file_id)
}
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
diff --git a/crates/hir-def/src/nameres/tests/incremental.rs b/crates/hir-def/src/nameres/tests/incremental.rs
index 34fa15f9e1..50751ab9c8 100644
--- a/crates/hir-def/src/nameres/tests/incremental.rs
+++ b/crates/hir-def/src/nameres/tests/incremental.rs
@@ -15,7 +15,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::new(ra_fixture_change.to_string()));
+ db.set_file_text(pos.file_id, Arc::from(ra_fixture_change));
{
let events = db.log_executed(|| {
@@ -96,7 +96,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
});
assert!(format!("{events:?}").contains("crate_def_map"), "{events:#?}")
}
- db.set_file_text(pos.file_id, Arc::new("m!(Y);".to_string()));
+ db.set_file_text(pos.file_id, Arc::from("m!(Y);"));
{
let events = db.log_executed(|| {
@@ -150,7 +150,7 @@ fn quux() { 92 }
m!(Y);
m!(Z);
"#;
- db.set_file_text(pos.file_id, Arc::new(new_text.to_string()));
+ db.set_file_text(pos.file_id, Arc::from(new_text));
{
let events = db.log_executed(|| {
diff --git a/crates/hir-def/src/test_db.rs b/crates/hir-def/src/test_db.rs
index 1cd652e7f0..6bfcd90970 100644
--- a/crates/hir-def/src/test_db.rs
+++ b/crates/hir-def/src/test_db.rs
@@ -71,7 +71,7 @@ impl fmt::Debug for TestDB {
impl panic::RefUnwindSafe for TestDB {}
impl FileLoader for TestDB {
- fn file_text(&self, file_id: FileId) -> Arc<String> {
+ fn file_text(&self, file_id: FileId) -> Arc<str> {
FileLoaderDelegate(self).file_text(file_id)
}
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
diff --git a/crates/hir-ty/src/test_db.rs b/crates/hir-ty/src/test_db.rs
index b994ddf15f..ca96a8d172 100644
--- a/crates/hir-ty/src/test_db.rs
+++ b/crates/hir-ty/src/test_db.rs
@@ -76,7 +76,7 @@ impl salsa::ParallelDatabase for TestDB {
impl panic::RefUnwindSafe for TestDB {}
impl FileLoader for TestDB {
- fn file_text(&self, file_id: FileId) -> Arc<String> {
+ fn file_text(&self, file_id: FileId) -> Arc<str> {
FileLoaderDelegate(self).file_text(file_id)
}
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
diff --git a/crates/hir-ty/src/tests.rs b/crates/hir-ty/src/tests.rs
index fee03ed0bd..af482e5cc6 100644
--- a/crates/hir-ty/src/tests.rs
+++ b/crates/hir-ty/src/tests.rs
@@ -572,10 +572,9 @@ fn salsa_bug() {
let x = 1;
x.push(1);
}
- "
- .to_string();
+ ";
- db.set_file_text(pos.file_id, Arc::new(new_text));
+ db.set_file_text(pos.file_id, Arc::from(new_text));
let module = db.module_for_file(pos.file_id);
let crate_def_map = module.def_map(&db);
diff --git a/crates/hir-ty/src/tests/incremental.rs b/crates/hir-ty/src/tests/incremental.rs
index 073d6d9be2..788eb30e28 100644
--- a/crates/hir-ty/src/tests/incremental.rs
+++ b/crates/hir-ty/src/tests/incremental.rs
@@ -33,10 +33,9 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
+
1
}
- "
- .to_string();
+ ";
- db.set_file_text(pos.file_id, Arc::new(new_text));
+ db.set_file_text(pos.file_id, Arc::from(new_text));
{
let events = db.log_executed(|| {
diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs
index a70a91c99e..b9f9cbd7fb 100644
--- a/crates/ide-db/src/lib.rs
+++ b/crates/ide-db/src/lib.rs
@@ -113,7 +113,7 @@ impl Upcast<dyn HirDatabase> for RootDatabase {
}
impl FileLoader for RootDatabase {
- fn file_text(&self, file_id: FileId) -> Arc<String> {
+ fn file_text(&self, file_id: FileId) -> Arc<str> {
FileLoaderDelegate(self).file_text(file_id)
}
fn resolve_path(&self, path: AnchoredPath<'_>) -> Option<FileId> {
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs
index 12f5e4e2a2..2557c65a10 100644
--- a/crates/ide-db/src/search.rs
+++ b/crates/ide-db/src/search.rs
@@ -438,11 +438,11 @@ impl<'a> FindUsages<'a> {
fn scope_files<'a>(
sema: &'a Semantics<'_, RootDatabase>,
scope: &'a SearchScope,
- ) -> impl Iterator<Item = (Arc<String>, FileId, TextRange)> + 'a {
+ ) -> impl Iterator<Item = (Arc<str>, FileId, TextRange)> + 'a {
scope.entries.iter().map(|(&file_id, &search_range)| {
let text = sema.db.file_text(file_id);
let search_range =
- search_range.unwrap_or_else(|| TextRange::up_to(TextSize::of(text.as_str())));
+ search_range.unwrap_or_else(|| TextRange::up_to(TextSize::of(&*text)));
(text, file_id, search_range)
})
@@ -553,7 +553,7 @@ impl<'a> FindUsages<'a> {
let text = sema.db.file_text(file_id);
let search_range =
- search_range.unwrap_or_else(|| TextRange::up_to(TextSize::of(text.as_str())));
+ search_range.unwrap_or_else(|| TextRange::up_to(TextSize::of(&*text)));
let tree = Lazy::new(|| sema.parse(file_id).syntax().clone());
let finder = &Finder::new("self");
diff --git a/crates/ide-ssr/src/lib.rs b/crates/ide-ssr/src/lib.rs
index d9834ee63a..a1945087d7 100644
--- a/crates/ide-ssr/src/lib.rs
+++ b/crates/ide-ssr/src/lib.rs
@@ -224,7 +224,7 @@ impl<'db> MatchFinder<'db> {
let file = self.sema.parse(file_id);
let mut res = Vec::new();
let file_text = self.sema.db.file_text(file_id);
- let mut remaining_text = file_text.as_str();
+ let mut remaining_text = &*file_text;
let mut base = 0;
let len = snippet.len() as u32;
while let Some(offset) = remaining_text.find(snippet) {
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index b227addc4c..d14cf83f0d 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -244,7 +244,7 @@ impl Analysis {
Err("Analysis::from_single_file has no target layout".into()),
None,
);
- change.change_file(file_id, Some(Arc::new(text)));
+ change.change_file(file_id, Some(Arc::from(text)));
change.set_crate_graph(crate_graph);
host.apply_change(change);
(host.analysis(), file_id)
@@ -263,7 +263,7 @@ impl Analysis {
}
/// Gets the text of the source file.
- pub fn file_text(&self, file_id: FileId) -> Cancellable<Arc<String>> {
+ pub fn file_text(&self, file_id: FileId) -> Cancellable<Arc<str>> {
self.with_db(|db| db.file_text(file_id))
}
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs
index 116e6b9751..0597302ca8 100644
--- a/crates/ide/src/status.rs
+++ b/crates/ide/src/status.rs
@@ -164,8 +164,8 @@ impl fmt::Display for FilesStats {
}
}
-impl StatCollect<FileId, Arc<String>> for FilesStats {
- fn collect_entry(&mut self, _: FileId, value: Option<Arc<String>>) {
+impl StatCollect<FileId, Arc<str>> for FilesStats {
+ fn collect_entry(&mut self, _: FileId, value: Option<Arc<str>>) {
self.total += 1;
self.size += value.unwrap().len();
}
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index 85a410f7b4..33c1b36f22 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -162,9 +162,9 @@ fn load_crate_graph(
let changes = vfs.take_changes();
for file in changes {
if file.exists() {
- let contents = vfs.file_contents(file.file_id).to_vec();
- if let Ok(text) = String::from_utf8(contents) {
- analysis_change.change_file(file.file_id, Some(Arc::new(text)))
+ let contents = vfs.file_contents(file.file_id);
+ if let Ok(text) = std::str::from_utf8(contents) {
+ analysis_change.change_file(file.file_id, Some(Arc::from(text)))
}
}
}
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 616d8fca5f..ff1cdacb7f 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -269,7 +269,7 @@ impl GlobalState {
String::from_utf8(bytes).ok().and_then(|text| {
let (text, line_endings) = LineEndings::normalize(text);
line_endings_map.insert(file.file_id, line_endings);
- Some(Arc::new(text))
+ Some(Arc::from(text))
})
} else {
None
diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs
index e8912b9079..6a69f70962 100644
--- a/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -65,7 +65,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 = Change::new();
- change.change_file(file_id, Some(Arc::new(text)));
+ change.change_file(file_id, Some(Arc::from(text)));
host.apply_change(change);
}
@@ -121,7 +121,7 @@ fn integrated_completion_benchmark() {
patch(&mut text, "db.struct_data(self.id)", "sel;\ndb.struct_data(self.id)")
+ "sel".len();
let mut change = Change::new();
- change.change_file(file_id, Some(Arc::new(text)));
+ change.change_file(file_id, Some(Arc::from(text)));
host.apply_change(change);
completion_offset
};
@@ -160,7 +160,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 = Change::new();
- change.change_file(file_id, Some(Arc::new(text)));
+ change.change_file(file_id, Some(Arc::from(text)));
host.apply_change(change);
completion_offset
};