aboutsummaryrefslogtreecommitdiffstats
path: root/src/regex/byte_range.rs
diff options
context:
space:
mode:
authorJonas Maier <jonas@x77.dev>2026-06-06 12:57:25 +0200
committerJonas Maier <jonas@x77.dev>2026-06-06 12:57:25 +0200
commit1c0c0c35f3dff0abc8ac24ec90dedf554697cec5 (patch)
tree81ceb1e5c913d468f6141ac373447d4519618840 /src/regex/byte_range.rs
parenta2e9e8647daa2622cf55a047c329027fcfc49bf8 (diff)
downloadpish-1c0c0c35f3dff0abc8ac24ec90dedf554697cec5.tar.gz
fix byterange bug, stuff is somehow slow suddenly
Diffstat (limited to 'src/regex/byte_range.rs')
-rw-r--r--src/regex/byte_range.rs48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/regex/byte_range.rs b/src/regex/byte_range.rs
index b7642c1..5123da5 100644
--- a/src/regex/byte_range.rs
+++ b/src/regex/byte_range.rs
@@ -36,45 +36,43 @@ impl ByteRange {
if ranges.is_empty() {
return vec![];
}
-
- let mut points: Vec<u8> = Vec::new();
+
+ let mut points: Vec<u16> = Vec::new();
for r in &ranges {
- points.push(r.from);
- if r.to != u8::MAX {
- points.push(r.to + 1);
- }
+ points.push(r.from as u16);
+ points.push((r.to as u16) + 1);
}
-
+
points.sort_unstable();
points.dedup();
-
+
let mut out = Vec::new();
-
+
for window in points.windows(2) {
let start = window[0];
let end_exclusive = window[1];
-
+
if start >= end_exclusive {
continue;
}
-
+
let mut active = false;
-
+
for r in &ranges {
- if r.from <= start && start <= r.to {
+ if r.from as u16 <= start && start <= r.to as u16 {
active = true;
break;
}
}
-
+
if active {
out.push(ByteRange {
- from: start,
- to: end_exclusive - 1,
+ from: start as u8,
+ to: (end_exclusive - 1) as u8,
});
}
}
-
+
out
}
}
@@ -94,6 +92,22 @@ fn byterange_test() {
);
}
+#[test]
+fn byterange_test_0_128() {
+ assert_eq!(
+ ByteRange::split_to_disjoint(vec![ByteRange::new_range(0, 128)]),
+ vec![ByteRange::new_range(0, 128)]
+ );
+}
+
+#[test]
+fn byterange_test_0_255() {
+ assert_eq!(
+ ByteRange::split_to_disjoint(vec![ByteRange::new_range(0, 255)]),
+ vec![ByteRange::new_range(0, 255)]
+ );
+}
+
impl std::fmt::Debug for ByteRange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.from == self.to {