From 58425f6ae203e19cfc48a9f67429f3fb3b07786d Mon Sep 17 00:00:00 2001 From: Euclid Ye Date: Sat, 2 Aug 2025 20:41:03 +0800 Subject: [PATCH] Replace all sort with unstable sort (#38427) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ["When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn’t allocate auxiliary memory."](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.sort) Binary also reduced by 1KB in Release. Testing: No behaviour change as semantically all current usage does not have any pair with `std::cmp::Ordering::Equal`. Signed-off-by: Euclid Ye --- components/compositing/webview_manager.rs | 2 +- components/constellation/constellation.rs | 2 +- components/constellation/webview_manager.rs | 2 +- ports/servoshell/desktop/app.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/compositing/webview_manager.rs b/components/compositing/webview_manager.rs index 201f9d1c5c5..544f90d489c 100644 --- a/components/compositing/webview_manager.rs +++ b/components/compositing/webview_manager.rs @@ -127,7 +127,7 @@ mod test { webviews: &WebViewManager, ) -> Vec<(WebViewId, WebView)> { let mut keys = webviews.webviews.keys().collect::>(); - keys.sort(); + keys.sort_unstable(); keys.iter() .map(|&id| (*id, webviews.webviews.get(id).cloned().unwrap())) .collect() diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 1e6ea7d94e5..c979ec01c95 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -5401,7 +5401,7 @@ where }; // In order to get repeatability, we sort the pipeline ids. let mut pipeline_ids: Vec<&PipelineId> = self.pipelines.keys().collect(); - pipeline_ids.sort(); + pipeline_ids.sort_unstable(); if let Some((ref mut rng, probability)) = self.random_pipeline_closure { if let Some(pipeline_id) = pipeline_ids.choose(rng) { if let Some(pipeline) = self.pipelines.get(pipeline_id) { diff --git a/components/constellation/webview_manager.rs b/components/constellation/webview_manager.rs index 3421de5a52f..f6673977740 100644 --- a/components/constellation/webview_manager.rs +++ b/components/constellation/webview_manager.rs @@ -99,7 +99,7 @@ mod test { webviews: &WebViewManager, ) -> Vec<(WebViewId, WebView)> { let mut keys = webviews.webviews.keys().collect::>(); - keys.sort(); + keys.sort_unstable(); keys.iter() .map(|&id| { ( diff --git a/ports/servoshell/desktop/app.rs b/ports/servoshell/desktop/app.rs index c81ed0583f6..2e560fbe539 100644 --- a/ports/servoshell/desktop/app.rs +++ b/ports/servoshell/desktop/app.rs @@ -814,7 +814,7 @@ fn load_userscripts(userscripts_directory: Option<&Path>) -> std::io::Result, _>>()?; - files.sort(); + files.sort_unstable(); for file in files { userscripts.push(UserScript { script: std::fs::read_to_string(&file)?,