From 54b2c12844ac5d34ae0debaae23ba0c2b2c257d8 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Mon, 7 Apr 2025 17:42:53 +0200 Subject: [PATCH] seq: fast_inc: split carry operation to a separate function This has no impact on performance, and will be useful for the `cat` usecase when we move this to uucore. --- src/uu/seq/src/seq.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 5178fe808..5501485b6 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -269,6 +269,7 @@ pub fn uu_app() -> Command { /// /// We also assume that there is enough space in val to expand if start needs /// to be updated. +#[inline] fn fast_inc(val: &mut [u8], start: usize, end: usize, inc: &[u8]) -> usize { // To avoid a lot of casts to signed integers, we make sure to decrement pos // as late as possible, so that it does not ever go negative. @@ -297,6 +298,14 @@ fn fast_inc(val: &mut [u8], start: usize, end: usize, inc: &[u8]) -> usize { if carry == 0 { return start.min(pos); } + + return fast_inc_one(val, start, pos); +} + +#[inline] +fn fast_inc_one(val: &mut [u8], start: usize, end: usize) -> usize { + let mut pos = end; + while pos > start { pos -= 1;