From ad9f894db32c6d606449b75944f18cd54a13addc Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 18 Jul 2026 15:20:43 +0100 Subject: [PATCH] Use with_slice_mut instead of looping over bytes --- rules/time/tgt_refcount.rs | 10 +++--- rules/unistd/tgt_refcount.rs | 10 +++--- tests/unit/out/refcount/sys_time.rs | 50 ++++++++++++----------------- 3 files changed, 28 insertions(+), 42 deletions(-) diff --git a/rules/time/tgt_refcount.rs b/rules/time/tgt_refcount.rs index bd49d01c..d8aa4204 100644 --- a/rules/time/tgt_refcount.rs +++ b/rules/time/tgt_refcount.rs @@ -96,12 +96,10 @@ fn f6(a0: Ptr, a1: usize, a2: Ptr, a3: Ptr) -> usize { if __text.is_empty() || __text.len() + 1 > a1 { 0 } else { - let mut __dst = a0.clone(); - for __b in __text.as_bytes() { - __dst.write(*__b); - __dst += 1; - } - __dst.write(0); + a0.with_slice_mut(__text.len() + 1, |__s| { + __s[..__text.len()].copy_from_slice(__text.as_bytes()); + __s[__text.len()] = 0; + }); __text.len() } } diff --git a/rules/unistd/tgt_refcount.rs b/rules/unistd/tgt_refcount.rs index c455ed6f..f7c6cf8c 100644 --- a/rules/unistd/tgt_refcount.rs +++ b/rules/unistd/tgt_refcount.rs @@ -22,13 +22,11 @@ fn f9(a0: Ptr, a1: usize) -> i32 { Ok(__name) => { let __bytes = __name.as_encoded_bytes(); let __n = __bytes.len().min(a1.saturating_sub(1)); - let mut __dst = a0.clone(); - for __b in &__bytes[..__n] { - __dst.write(*__b); - __dst += 1; - } if a1 > 0 { - __dst.write(0); + a0.with_slice_mut(__n + 1, |__s| { + __s[..__n].copy_from_slice(&__bytes[..__n]); + __s[__n] = 0; + }); } 0 } diff --git a/tests/unit/out/refcount/sys_time.rs b/tests/unit/out/refcount/sys_time.rs index a0f8ac7f..a26480fb 100644 --- a/tests/unit/out/refcount/sys_time.rs +++ b/tests/unit/out/refcount/sys_time.rs @@ -182,12 +182,10 @@ pub fn test_strftime_5() { if __text.is_empty() || __text.len() + 1 > ::std::mem::size_of::<[u8; 64]>() { 0 } else { - let mut __dst = (buf.as_pointer() as Ptr).clone(); - for __b in __text.as_bytes() { - __dst.write(*__b); - __dst += 1; - } - __dst.write(0); + (buf.as_pointer() as Ptr).with_slice_mut(__text.len() + 1, |__s| { + __s[..__text.len()].copy_from_slice(__text.as_bytes()); + __s[__text.len()] = 0; + }); __text.len() } } > 0_usize) as i32) @@ -210,12 +208,10 @@ pub fn test_strftime_5() { if __text.is_empty() || __text.len() + 1 > ::std::mem::size_of::<[u8; 64]>() { 0 } else { - let mut __dst = (buf.as_pointer() as Ptr).clone(); - for __b in __text.as_bytes() { - __dst.write(*__b); - __dst += 1; - } - __dst.write(0); + (buf.as_pointer() as Ptr).with_slice_mut(__text.len() + 1, |__s| { + __s[..__text.len()].copy_from_slice(__text.as_bytes()); + __s[__text.len()] = 0; + }); __text.len() } } > 0_usize) as i32) @@ -238,12 +234,10 @@ pub fn test_strftime_5() { if __text.is_empty() || __text.len() + 1 > ::std::mem::size_of::<[u8; 64]>() { 0 } else { - let mut __dst = (buf.as_pointer() as Ptr).clone(); - for __b in __text.as_bytes() { - __dst.write(*__b); - __dst += 1; - } - __dst.write(0); + (buf.as_pointer() as Ptr).with_slice_mut(__text.len() + 1, |__s| { + __s[..__text.len()].copy_from_slice(__text.as_bytes()); + __s[__text.len()] = 0; + }); __text.len() } } > 0_usize) as i32) @@ -264,12 +258,10 @@ pub fn test_strftime_5() { if __text.is_empty() || __text.len() + 1 > ::std::mem::size_of::<[u8; 64]>() { 0 } else { - let mut __dst = (buf.as_pointer() as Ptr).clone(); - for __b in __text.as_bytes() { - __dst.write(*__b); - __dst += 1; - } - __dst.write(0); + (buf.as_pointer() as Ptr).with_slice_mut(__text.len() + 1, |__s| { + __s[..__text.len()].copy_from_slice(__text.as_bytes()); + __s[__text.len()] = 0; + }); __text.len() } } > 0_usize) as i32) @@ -295,12 +287,10 @@ pub fn test_strftime_5() { if __text.is_empty() || __text.len() + 1 > ::std::mem::size_of::<[u8; 4]>() { 0 } else { - let mut __dst = (small.as_pointer() as Ptr).clone(); - for __b in __text.as_bytes() { - __dst.write(*__b); - __dst += 1; - } - __dst.write(0); + (small.as_pointer() as Ptr).with_slice_mut(__text.len() + 1, |__s| { + __s[..__text.len()].copy_from_slice(__text.as_bytes()); + __s[__text.len()] = 0; + }); __text.len() } } == 0_usize) as i32)