From bcca4045511dd3d3e1fd3db7c14613300ced4bf9 Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Thu, 9 Oct 2025 15:34:27 +0300 Subject: [PATCH] Avoid string allocation in sorter record comparison --- core/vdbe/sorter.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/vdbe/sorter.rs b/core/vdbe/sorter.rs index 0294787f1..a55cb656a 100644 --- a/core/vdbe/sorter.rs +++ b/core/vdbe/sorter.rs @@ -686,8 +686,9 @@ impl Ord for SortableImmutableRecord { let cmp = match (this_key_value, other_key_value) { (ValueRef::Text(left, _), ValueRef::Text(right, _)) => collation.compare_strings( - &String::from_utf8_lossy(left), - &String::from_utf8_lossy(right), + // SAFETY: these were checked to be valid UTF-8 on construction. + unsafe { std::str::from_utf8_unchecked(left) }, + unsafe { std::str::from_utf8_unchecked(right) }, ), _ => this_key_value.partial_cmp(&other_key_value).unwrap(), };