From b8018aebd146bef24fd754cbabb9372084cc420c Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 18 Mar 2026 23:40:54 +0100 Subject: [PATCH] sort: add collation key arena storage to LineData Add collation_key_buffer (arena) and collation_key_ends (offsets) to LineData and RecycledChunk, with a collation_key() accessor. All sort keys for a chunk are stored in a single Vec to avoid millions of small heap allocations. --- src/uu/sort/src/chunks.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/uu/sort/src/chunks.rs b/src/uu/sort/src/chunks.rs index ce6b2118b..48bd4abca 100644 --- a/src/uu/sort/src/chunks.rs +++ b/src/uu/sort/src/chunks.rs @@ -62,6 +62,11 @@ pub struct LineData<'a> { impl LineData<'_> { /// Get the collation sort key for a line at the given index. pub fn collation_key(&self, index: usize) -> &[u8] { + debug_assert!( + index < self.collation_key_ends.len(), + "collation_key index {index} out of bounds (len {})", + self.collation_key_ends.len() + ); let start = if index == 0 { 0 } else {