MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / copy_from

Method copy_from

cranelift/entity/src/list.rs:489–526  ·  view source on GitHub ↗

Copies a slice from an entity list in the same pool to a position in this one. Will panic if `self` is the same list as `other`.

(
        &mut self,
        other: &Self,
        slice: impl core::ops::RangeBounds<usize>,
        index: usize,
        pool: &mut ListPool<T>,
    )

Source from the content-addressed store, hash-verified

487 ///
488 /// Will panic if `self` is the same list as `other`.
489 pub fn copy_from(
490 &mut self,
491 other: &Self,
492 slice: impl core::ops::RangeBounds<usize>,
493 index: usize,
494 pool: &mut ListPool<T>,
495 ) {
496 assert!(
497 index <= self.len(pool),
498 "attempted to copy a slice out of bounds of `self`"
499 );
500 assert_ne!(
501 self.index, other.index,
502 "cannot copy within one `EntityList`"
503 );
504
505 let (other_index, other_len) = (other.index, other.len(pool));
506
507 let start = match slice.start_bound() {
508 core::ops::Bound::Included(&x) => x,
509 core::ops::Bound::Excluded(&x) => x + 1,
510 core::ops::Bound::Unbounded => 0,
511 } + other_index as usize;
512 let end = match slice.end_bound() {
513 core::ops::Bound::Included(&x) => x + 1,
514 core::ops::Bound::Excluded(&x) => x,
515 core::ops::Bound::Unbounded => other_len,
516 } + other_index as usize;
517 let count = end - start;
518 assert!(
519 count <= other_len,
520 "attempted to copy a slice from out of bounds of `other`"
521 );
522
523 self.grow_at(index, count, pool);
524 pool.data
525 .copy_within(start..end, index + self.index as usize);
526 }
527
528 /// Inserts an element as position `index` in the list, shifting all elements after it to the
529 /// right.

Callers 3

copy_fromFunction · 0.45
copy_from_selfFunction · 0.45
export_fooFunction · 0.45

Calls 3

grow_atMethod · 0.80
copy_withinMethod · 0.80
lenMethod · 0.45

Tested by 1

copy_fromFunction · 0.36