mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
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.
This commit is contained in:
parent
03b2cab650
commit
54b2c12844
1 changed files with 9 additions and 0 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue