mirror of
https://github.com/rui314/mold.git
synced 2026-11-09 04:49:33 -10:00
Consume mutable slice prefixes with split_off_mut
This commit is contained in:
1 parent
6f8aa2f99d
commit
3d06f6484e
7 files changed
+21
-27
No files matched your search
@@ -66,9 +66,9 @@ pub fn copy_buf<E: Arch>(ctx: &Context<E>, buf: &mut [u8]) {
|
||||
let start = chunk[0].offset as usize;
|
||||
let last = chunk.last().unwrap();
|
||||
let end = last.offset as usize + last.name.len() + 1;
|
||||
let (_, tail) = std::mem::take(&mut rest).split_at_mut(start - pos);
|
||||
let (out, tail) = tail.split_at_mut(end - start);
|
||||
rest = tail;
|
||||
rest.split_off_mut(..start - pos).unwrap();
|
||||
let out = rest.split_off_mut(..end - start).unwrap();
|
||||
|
||||
pos = end;
|
||||
(chunk, out)
|
||||
})
|
||||
|
||||
@@ -281,9 +281,8 @@ pub fn copy_buf<E: Arch>(ctx: &Context<E>, buf: &mut [u8], hdr_buf: Option<&mut
|
||||
for (item, file) in items.iter_mut().zip(&ctx.objs) {
|
||||
if !file.fdes.is_empty() {
|
||||
let len = file.fdes.len() * 8;
|
||||
let (own, tail) = std::mem::take(&mut rest).split_at_mut(len);
|
||||
let own = rest.split_off_mut(..len).unwrap();
|
||||
item.hdr_entries = Some(own);
|
||||
rest = tail;
|
||||
}
|
||||
}
|
||||
debug_assert!(rest.is_empty());
|
||||
|
||||
@@ -57,9 +57,8 @@ pub fn collect_relocs<E: Arch>(ctx: &Context<E>) -> Vec<ElfRel<E>> {
|
||||
let hdr = ctx.chunk_header(id);
|
||||
let count = (hdr.num_dynrels - hdr.num_relrs) as usize;
|
||||
if count != 0 {
|
||||
let (slots, tail) = std::mem::take(&mut rest).split_at_mut(count);
|
||||
let slots = rest.split_off_mut(..count).unwrap();
|
||||
chunks::write_dynrels(ctx, id, slots);
|
||||
rest = tail;
|
||||
}
|
||||
}
|
||||
debug_assert!(rest.is_empty());
|
||||
@@ -162,9 +161,8 @@ pub fn copy_buf<E: Arch>(ctx: &Context<E>, buf: &mut [u8]) {
|
||||
let hdr = ctx.chunk_header(id);
|
||||
let count = (hdr.num_dynrels - hdr.num_relrs) as usize;
|
||||
if count != 0 {
|
||||
let (slots, tail) = std::mem::take(&mut rest).split_at_mut(count * size);
|
||||
let slots = rest.split_off_mut(..count * size).unwrap();
|
||||
chunks::write_dynrels(ctx, id, rels_from_bytes_mut::<E>(slots));
|
||||
rest = tail;
|
||||
}
|
||||
}
|
||||
debug_assert!(rest.is_empty());
|
||||
|
||||
@@ -223,10 +223,8 @@ fn carve<'a>(rest: &mut &'a mut [u8], pos: &mut usize, start: usize, len: usize)
|
||||
if len == 0 {
|
||||
return &mut [];
|
||||
}
|
||||
let buf = std::mem::take(rest);
|
||||
let (_, buf) = buf.split_at_mut(start - *pos);
|
||||
let (piece, tail) = buf.split_at_mut(len);
|
||||
*rest = tail;
|
||||
rest.split_off_mut(..start - *pos).unwrap();
|
||||
let piece = rest.split_off_mut(..len).unwrap();
|
||||
*pos = start + len;
|
||||
piece
|
||||
}
|
||||
|
||||
+6
-6
@@ -459,10 +459,10 @@ pub fn split_at_offsets<'a, T>(buf: &'a mut [T], offsets: &[u64]) -> Vec<&'a mut
|
||||
let start = start as usize;
|
||||
let end = offsets.get(i + 1).map_or(rest.len() + pos, |&e| e as usize);
|
||||
debug_assert!(pos <= start && start <= end);
|
||||
let (_, tail) = std::mem::take(&mut rest).split_at_mut(start - pos);
|
||||
let (slice, tail) = tail.split_at_mut(end - start);
|
||||
rest.split_off_mut(..start - pos).unwrap();
|
||||
let slice = rest.split_off_mut(..end - start).unwrap();
|
||||
slices.push(slice);
|
||||
rest = tail;
|
||||
|
||||
pos = end;
|
||||
}
|
||||
slices
|
||||
@@ -479,10 +479,10 @@ pub fn split_ranges<'a>(buf: &'a mut [u8], ranges: &[Range<u64>]) -> Vec<&'a mut
|
||||
for i in order {
|
||||
let r = &ranges[i];
|
||||
assert!(r.start >= pos, "overlapping output ranges");
|
||||
let (_, tail) = std::mem::take(&mut rest).split_at_mut((r.start - pos) as usize);
|
||||
let (slice, tail) = tail.split_at_mut((r.end - r.start) as usize);
|
||||
rest.split_off_mut(..(r.start - pos) as usize).unwrap();
|
||||
let slice = rest.split_off_mut(..(r.end - r.start) as usize).unwrap();
|
||||
result[i] = Some(slice);
|
||||
rest = tail;
|
||||
|
||||
pos = r.end;
|
||||
}
|
||||
result.into_iter().map(|s| s.unwrap()).collect()
|
||||
|
||||
+3
-4
@@ -1036,8 +1036,8 @@ pub fn create_merged_sections<E: Arch>(ctx: &mut Context<E>) {
|
||||
let parts: Vec<_> = fragments
|
||||
.into_iter()
|
||||
.map(|fragments| {
|
||||
let (head, tail) = std::mem::take(&mut rest).split_at_mut(fragments.len());
|
||||
rest = tail;
|
||||
let head = rest.split_off_mut(..fragments.len()).unwrap();
|
||||
|
||||
let first = offset;
|
||||
offset += fragments.len();
|
||||
(first, head, fragments)
|
||||
@@ -1391,9 +1391,8 @@ pub fn create_output_sections<E: Arch>(ctx: &mut Context<E>) {
|
||||
let mut rest = members.as_mut_slice();
|
||||
let mut slices = Vec::with_capacity(parts.len());
|
||||
for g in &parts {
|
||||
let (head, tail) = rest.split_at_mut(g.members.len());
|
||||
let head = rest.split_off_mut(..g.members.len()).unwrap();
|
||||
slices.push(head);
|
||||
rest = tail;
|
||||
}
|
||||
parts.par_iter().zip(slices).for_each(|(g, slice)| {
|
||||
slice.copy_from_slice(&g.members);
|
||||
|
||||
@@ -27,10 +27,10 @@ pub(crate) fn stable_partition<T: Copy + Send + Sync>(
|
||||
.iter()
|
||||
.zip(matches.chunks(BLOCK))
|
||||
.map(|(&count, flags)| {
|
||||
let (matched, tail) = std::mem::take(&mut yes).split_at_mut(count);
|
||||
yes = tail;
|
||||
let (unmatched, tail) = std::mem::take(&mut no).split_at_mut(flags.len() - count);
|
||||
no = tail;
|
||||
let matched = yes.split_off_mut(..count).unwrap();
|
||||
|
||||
let unmatched = no.split_off_mut(..flags.len() - count).unwrap();
|
||||
|
||||
(matched, unmatched)
|
||||
})
|
||||
.collect();
|
||||
|
||||
Reference in new issue
Block a user