From 8d7b7e51247a37a6e2e6cda0e5d95893f6cedde1 Mon Sep 17 00:00:00 2001 From: Cylae <13425054+Cylae@users.noreply.github.com> Date: Wed, 9 Sep 2026 00:54:48 +0000 Subject: [PATCH] perf: pre-allocate memory and sort users in list_users Pre-allocate vector capacity according to the user map length in UserManager::list_users to avoid reallocations during collection, and sort returned users deterministically by username for consistent rendering in web and CLI interface handlers. --- server_manager/src/core/users.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server_manager/src/core/users.rs b/server_manager/src/core/users.rs index 46ff68a..9a98731 100644 --- a/server_manager/src/core/users.rs +++ b/server_manager/src/core/users.rs @@ -363,7 +363,10 @@ impl UserManager { } pub fn list_users(&self) -> Vec<&User> { - self.users.values().collect() + let mut list = Vec::with_capacity(self.users.len()); + list.extend(self.users.values()); + list.sort_by(|a, b| a.username.cmp(&b.username)); + list } }