aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorLaurenČ›iu Nicola <[email protected]>2020-12-29 12:35:49 +0000
committerLaurenČ›iu Nicola <[email protected]>2020-12-29 12:35:49 +0000
commit42c24ff25f391a1e3662ce226d510aedc9d1f0e4 (patch)
tree004195234e0409ddc54514a2e8b737ed8e16b74e /crates/hir_def
parentef1177c5b5a7ced9866025a51c10e4375e2a37fd (diff)
Avoid a couple of allocations
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/import_map.rs27
-rw-r--r--crates/hir_def/src/nameres.rs2
2 files changed, 15 insertions, 14 deletions
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 {
262} 262}
263 263
264impl Query { 264impl Query {
265 pub fn new(query: &str) -> Self { 265 pub fn new(query: String) -> Self {
266 let lowercased = query.to_lowercase();
266 Self { 267 Self {
267 query: query.to_string(), 268 query,
268 lowercased: query.to_lowercase(), 269 lowercased,
269 name_only: false, 270 name_only: false,
270 search_mode: SearchMode::Contains, 271 search_mode: SearchMode::Contains,
271 case_sensitive: false, 272 case_sensitive: false,
@@ -774,7 +775,7 @@ mod tests {
774 check_search( 775 check_search(
775 ra_fixture, 776 ra_fixture,
776 "main", 777 "main",
777 Query::new("fmt").search_mode(SearchMode::Fuzzy), 778 Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
778 expect![[r#" 779 expect![[r#"
779 dep::fmt (t) 780 dep::fmt (t)
780 dep::Fmt (t) 781 dep::Fmt (t)
@@ -789,7 +790,7 @@ mod tests {
789 check_search( 790 check_search(
790 ra_fixture, 791 ra_fixture,
791 "main", 792 "main",
792 Query::new("fmt").search_mode(SearchMode::Equals), 793 Query::new("fmt".to_string()).search_mode(SearchMode::Equals),
793 expect![[r#" 794 expect![[r#"
794 dep::fmt (t) 795 dep::fmt (t)
795 dep::Fmt (t) 796 dep::Fmt (t)
@@ -802,7 +803,7 @@ mod tests {
802 check_search( 803 check_search(
803 ra_fixture, 804 ra_fixture,
804 "main", 805 "main",
805 Query::new("fmt").search_mode(SearchMode::Contains), 806 Query::new("fmt".to_string()).search_mode(SearchMode::Contains),
806 expect![[r#" 807 expect![[r#"
807 dep::fmt (t) 808 dep::fmt (t)
808 dep::Fmt (t) 809 dep::Fmt (t)
@@ -843,7 +844,7 @@ mod tests {
843 check_search( 844 check_search(
844 ra_fixture, 845 ra_fixture,
845 "main", 846 "main",
846 Query::new("fmt"), 847 Query::new("fmt".to_string()),
847 expect![[r#" 848 expect![[r#"
848 dep::fmt (t) 849 dep::fmt (t)
849 dep::Fmt (t) 850 dep::Fmt (t)
@@ -857,7 +858,7 @@ mod tests {
857 check_search( 858 check_search(
858 ra_fixture, 859 ra_fixture,
859 "main", 860 "main",
860 Query::new("fmt").name_only(), 861 Query::new("fmt".to_string()).name_only(),
861 expect![[r#" 862 expect![[r#"
862 dep::fmt (t) 863 dep::fmt (t)
863 dep::Fmt (t) 864 dep::Fmt (t)
@@ -881,7 +882,7 @@ mod tests {
881 check_search( 882 check_search(
882 ra_fixture, 883 ra_fixture,
883 "main", 884 "main",
884 Query::new("FMT"), 885 Query::new("FMT".to_string()),
885 expect![[r#" 886 expect![[r#"
886 dep::fmt (t) 887 dep::fmt (t)
887 dep::fmt (v) 888 dep::fmt (v)
@@ -893,7 +894,7 @@ mod tests {
893 check_search( 894 check_search(
894 ra_fixture, 895 ra_fixture,
895 "main", 896 "main",
896 Query::new("FMT").case_sensitive(), 897 Query::new("FMT".to_string()).case_sensitive(),
897 expect![[r#" 898 expect![[r#"
898 dep::FMT (t) 899 dep::FMT (t)
899 dep::FMT (v) 900 dep::FMT (v)
@@ -922,7 +923,7 @@ mod tests {
922 pub fn no() {} 923 pub fn no() {}
923 "#, 924 "#,
924 "main", 925 "main",
925 Query::new("").limit(2), 926 Query::new("".to_string()).limit(2),
926 expect![[r#" 927 expect![[r#"
927 dep::fmt (t) 928 dep::fmt (t)
928 dep::Fmt (t) 929 dep::Fmt (t)
@@ -943,7 +944,7 @@ mod tests {
943 check_search( 944 check_search(
944 ra_fixture, 945 ra_fixture,
945 "main", 946 "main",
946 Query::new("FMT"), 947 Query::new("FMT".to_string()),
947 expect![[r#" 948 expect![[r#"
948 dep::fmt (t) 949 dep::fmt (t)
949 dep::fmt (v) 950 dep::fmt (v)
@@ -955,7 +956,7 @@ mod tests {
955 check_search( 956 check_search(
956 ra_fixture, 957 ra_fixture,
957 "main", 958 "main",
958 Query::new("FMT").exclude_import_kind(ImportKind::Adt), 959 Query::new("FMT".to_string()).exclude_import_kind(ImportKind::Adt),
959 expect![[r#""#]], 960 expect![[r#""#]],
960 ); 961 );
961 } 962 }
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 {
249 buf.push_str(" _"); 249 buf.push_str(" _");
250 } 250 }
251 251
252 buf.push_str("\n"); 252 buf.push('\n');
253 } 253 }
254 254
255 for (name, child) in map.modules[module].children.iter() { 255 for (name, child) in map.modules[module].children.iter() {