Unnamed repository; edit this file 'description' to name the repository.
Perf + Test Case RE: ShoyuVanilla
Flora Hill 2 months ago
parent f43d471 · commit 75a8d56
-rw-r--r--crates/ide-db/src/imports/insert_use/tests.rs10
-rw-r--r--crates/ide-db/src/imports/merge_imports.rs10
2 files changed, 15 insertions, 5 deletions
diff --git a/crates/ide-db/src/imports/insert_use/tests.rs b/crates/ide-db/src/imports/insert_use/tests.rs
index 7763d1e595..6c7b97458d 100644
--- a/crates/ide-db/src/imports/insert_use/tests.rs
+++ b/crates/ide-db/src/imports/insert_use/tests.rs
@@ -1529,6 +1529,16 @@ fn merge_gated_imports_with_different_values() {
}
#[test]
+fn merge_gated_imports_different_order() {
+ check_merge(
+ r#"#[cfg(a)] #[cfg(b)] use foo::bar;"#,
+ r#"#[cfg(b)] #[cfg(a)] use foo::baz;"#,
+ r#"#[cfg(a)] #[cfg(b)] use foo::{bar, baz};"#,
+ MergeBehavior::Crate,
+ );
+}
+
+#[test]
fn merge_into_existing_cfg_import() {
check(
r#"foo::Foo"#,
diff --git a/crates/ide-db/src/imports/merge_imports.rs b/crates/ide-db/src/imports/merge_imports.rs
index d63b239ff4..3301719f5c 100644
--- a/crates/ide-db/src/imports/merge_imports.rs
+++ b/crates/ide-db/src/imports/merge_imports.rs
@@ -4,7 +4,7 @@ use std::cmp::Ordering;
use itertools::{EitherOrBoth, Itertools};
use parser::T;
use syntax::{
- Direction, SyntaxElement, algo,
+ Direction, SyntaxElement, ToSmolStr, algo,
ast::{
self, AstNode, HasAttrs, HasName, HasVisibility, PathSegmentKind, edit_in_place::Removable,
make,
@@ -691,10 +691,10 @@ pub fn eq_attrs(
attrs0: impl Iterator<Item = ast::Attr>,
attrs1: impl Iterator<Item = ast::Attr>,
) -> bool {
- let mut attrs0: Vec<_> = attrs0.map(|attr| attr.syntax().text().to_string()).collect();
- let mut attrs1: Vec<_> = attrs1.map(|attr| attr.syntax().text().to_string()).collect();
- attrs0.sort();
- attrs1.sort();
+ let mut attrs0: Vec<_> = attrs0.map(|attr| attr.syntax().text().to_smolstr()).collect();
+ let mut attrs1: Vec<_> = attrs1.map(|attr| attr.syntax().text().to_smolstr()).collect();
+ attrs0.sort_unstable();
+ attrs1.sort_unstable();
attrs0 == attrs1
}