Skip to content

Commit 70f1696

Browse files
authored
Use with_slice_mut instead of looping over bytes (#268)
1 parent 056785e commit 70f1696

3 files changed

Lines changed: 28 additions & 42 deletions

File tree

‎rules/time/tgt_refcount.rs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,10 @@ fn f6(a0: Ptr<u8>, a1: usize, a2: Ptr<u8>, a3: Ptr<Tm>) -> usize {
9696
if __text.is_empty() || __text.len() + 1 > a1 {
9797
0
9898
} else {
99-
let mut __dst = a0.clone();
100-
for __b in __text.as_bytes() {
101-
__dst.write(*__b);
102-
__dst += 1;
103-
}
104-
__dst.write(0);
99+
a0.with_slice_mut(__text.len() + 1, |__s| {
100+
__s[..__text.len()].copy_from_slice(__text.as_bytes());
101+
__s[__text.len()] = 0;
102+
});
105103
__text.len()
106104
}
107105
}

‎rules/unistd/tgt_refcount.rs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ fn f9(a0: Ptr<u8>, a1: usize) -> i32 {
2222
Ok(__name) => {
2323
let __bytes = __name.as_encoded_bytes();
2424
let __n = __bytes.len().min(a1.saturating_sub(1));
25-
let mut __dst = a0.clone();
26-
for __b in &__bytes[..__n] {
27-
__dst.write(*__b);
28-
__dst += 1;
29-
}
3025
if a1 > 0 {
31-
__dst.write(0);
26+
a0.with_slice_mut(__n + 1, |__s| {
27+
__s[..__n].copy_from_slice(&__bytes[..__n]);
28+
__s[__n] = 0;
29+
});
3230
}
3331
0
3432
}

‎tests/unit/out/refcount/sys_time.rs‎

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,10 @@ pub fn test_strftime_5() {
182182
if __text.is_empty() || __text.len() + 1 > ::std::mem::size_of::<[u8; 64]>() {
183183
0
184184
} else {
185-
let mut __dst = (buf.as_pointer() as Ptr<u8>).clone();
186-
for __b in __text.as_bytes() {
187-
__dst.write(*__b);
188-
__dst += 1;
189-
}
190-
__dst.write(0);
185+
(buf.as_pointer() as Ptr<u8>).with_slice_mut(__text.len() + 1, |__s| {
186+
__s[..__text.len()].copy_from_slice(__text.as_bytes());
187+
__s[__text.len()] = 0;
188+
});
191189
__text.len()
192190
}
193191
} > 0_usize) as i32)
@@ -210,12 +208,10 @@ pub fn test_strftime_5() {
210208
if __text.is_empty() || __text.len() + 1 > ::std::mem::size_of::<[u8; 64]>() {
211209
0
212210
} else {
213-
let mut __dst = (buf.as_pointer() as Ptr<u8>).clone();
214-
for __b in __text.as_bytes() {
215-
__dst.write(*__b);
216-
__dst += 1;
217-
}
218-
__dst.write(0);
211+
(buf.as_pointer() as Ptr<u8>).with_slice_mut(__text.len() + 1, |__s| {
212+
__s[..__text.len()].copy_from_slice(__text.as_bytes());
213+
__s[__text.len()] = 0;
214+
});
219215
__text.len()
220216
}
221217
} > 0_usize) as i32)
@@ -238,12 +234,10 @@ pub fn test_strftime_5() {
238234
if __text.is_empty() || __text.len() + 1 > ::std::mem::size_of::<[u8; 64]>() {
239235
0
240236
} else {
241-
let mut __dst = (buf.as_pointer() as Ptr<u8>).clone();
242-
for __b in __text.as_bytes() {
243-
__dst.write(*__b);
244-
__dst += 1;
245-
}
246-
__dst.write(0);
237+
(buf.as_pointer() as Ptr<u8>).with_slice_mut(__text.len() + 1, |__s| {
238+
__s[..__text.len()].copy_from_slice(__text.as_bytes());
239+
__s[__text.len()] = 0;
240+
});
247241
__text.len()
248242
}
249243
} > 0_usize) as i32)
@@ -264,12 +258,10 @@ pub fn test_strftime_5() {
264258
if __text.is_empty() || __text.len() + 1 > ::std::mem::size_of::<[u8; 64]>() {
265259
0
266260
} else {
267-
let mut __dst = (buf.as_pointer() as Ptr<u8>).clone();
268-
for __b in __text.as_bytes() {
269-
__dst.write(*__b);
270-
__dst += 1;
271-
}
272-
__dst.write(0);
261+
(buf.as_pointer() as Ptr<u8>).with_slice_mut(__text.len() + 1, |__s| {
262+
__s[..__text.len()].copy_from_slice(__text.as_bytes());
263+
__s[__text.len()] = 0;
264+
});
273265
__text.len()
274266
}
275267
} > 0_usize) as i32)
@@ -295,12 +287,10 @@ pub fn test_strftime_5() {
295287
if __text.is_empty() || __text.len() + 1 > ::std::mem::size_of::<[u8; 4]>() {
296288
0
297289
} else {
298-
let mut __dst = (small.as_pointer() as Ptr<u8>).clone();
299-
for __b in __text.as_bytes() {
300-
__dst.write(*__b);
301-
__dst += 1;
302-
}
303-
__dst.write(0);
290+
(small.as_pointer() as Ptr<u8>).with_slice_mut(__text.len() + 1, |__s| {
291+
__s[..__text.len()].copy_from_slice(__text.as_bytes());
292+
__s[__text.len()] = 0;
293+
});
304294
__text.len()
305295
}
306296
} == 0_usize) as i32)

0 commit comments

Comments
 (0)