From 42c24ff25f391a1e3662ce226d510aedc9d1f0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 29 Dec 2020 14:35:49 +0200 Subject: Avoid a couple of allocations --- crates/hir_def/src/import_map.rs | 27 ++++++++++++++------------- crates/hir_def/src/nameres.rs | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/import_map.rs b/crates/hir_def/src/import_map.rs index fdc681d6c..c4dc894df 100644 --- a/crates/hir_def/src/import_map.rs +++ b/crates/hir_def/src/import_map.rs @@ -262,10 +262,11 @@ pub struct Query { } impl Query { - pub fn new(query: &str) -> Self { + pub fn new(query: String) -> Self { + let lowercased = query.to_lowercase(); Self { - query: query.to_string(), - lowercased: query.to_lowercase(), + query, + lowercased, name_only: false, search_mode: SearchMode::Contains, case_sensitive: false, @@ -774,7 +775,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("fmt").search_mode(SearchMode::Fuzzy), + Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -789,7 +790,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("fmt").search_mode(SearchMode::Equals), + Query::new("fmt".to_string()).search_mode(SearchMode::Equals), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -802,7 +803,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("fmt").search_mode(SearchMode::Contains), + Query::new("fmt".to_string()).search_mode(SearchMode::Contains), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -843,7 +844,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("fmt"), + Query::new("fmt".to_string()), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -857,7 +858,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("fmt").name_only(), + Query::new("fmt".to_string()).name_only(), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -881,7 +882,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("FMT"), + Query::new("FMT".to_string()), expect![[r#" dep::fmt (t) dep::fmt (v) @@ -893,7 +894,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("FMT").case_sensitive(), + Query::new("FMT".to_string()).case_sensitive(), expect![[r#" dep::FMT (t) dep::FMT (v) @@ -922,7 +923,7 @@ mod tests { pub fn no() {} "#, "main", - Query::new("").limit(2), + Query::new("".to_string()).limit(2), expect![[r#" dep::fmt (t) dep::Fmt (t) @@ -943,7 +944,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("FMT"), + Query::new("FMT".to_string()), expect![[r#" dep::fmt (t) dep::fmt (v) @@ -955,7 +956,7 @@ mod tests { check_search( ra_fixture, "main", - Query::new("FMT").exclude_import_kind(ImportKind::Adt), + Query::new("FMT".to_string()).exclude_import_kind(ImportKind::Adt), expect![[r#""#]], ); } diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index ffd0381d4..9bf358775 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs @@ -249,7 +249,7 @@ impl CrateDefMap { buf.push_str(" _"); } - buf.push_str("\n"); + buf.push('\n'); } for (name, child) in map.modules[module].children.iter() { -- cgit v1.2.3