MCPcopy Index your code
hub / github.com/RustPython/RustPython / replace_in_place

Method replace_in_place

crates/vm/src/bytes_inner.rs:799–824  ·  view source on GitHub ↗
(&self, from: Self, to: Self, max_count: Option<usize>)

Source from the content-addressed store, hash-verified

797 }
798
799 pub fn replace_in_place(&self, from: Self, to: Self, max_count: Option<usize>) -> Vec<u8> {
800 let len = from.len();
801 let mut iter = self.elements.find_iter(&from.elements);
802
803 let mut new = if let Some(offset) = iter.next() {
804 let mut new = self.elements.clone();
805 new[offset..offset + len].clone_from_slice(to.elements.as_slice());
806 if max_count == Some(1) {
807 return new;
808 } else {
809 new
810 }
811 } else {
812 return self.elements.clone();
813 };
814
815 let mut count = max_count.unwrap_or(usize::MAX) - 1;
816 for offset in iter {
817 new[offset..offset + len].clone_from_slice(to.elements.as_slice());
818 count -= 1;
819 if count == 0 {
820 break;
821 }
822 }
823 new
824 }
825
826 fn replace_general(
827 &self,

Callers 1

replaceMethod · 0.80

Calls 6

find_iterMethod · 0.80
SomeClass · 0.50
lenMethod · 0.45
nextMethod · 0.45
cloneMethod · 0.45
as_sliceMethod · 0.45

Tested by

no test coverage detected