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

Method replace_delete

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

Source from the content-addressed store, hash-verified

768 }
769
770 fn replace_delete(&self, from: Self, max_count: Option<usize>) -> Vec<u8> {
771 let count = count_substring(
772 self.elements.as_slice(),
773 from.elements.as_slice(),
774 max_count,
775 );
776 if count == 0 {
777 // no matches
778 return self.elements.clone();
779 }
780
781 let result_len = self.len() - (count * from.len());
782 debug_assert!(self.len() >= count * from.len());
783
784 let mut result = Vec::with_capacity(result_len);
785 let mut last_end = 0;
786 let mut count = count;
787 for offset in self.elements.find_iter(&from.elements) {
788 result.extend_from_slice(&self.elements[last_end..offset]);
789 last_end = offset + from.len();
790 count -= 1;
791 if count == 0 {
792 break;
793 }
794 }
795 result.extend_from_slice(&self.elements[last_end..]);
796 result
797 }
798
799 pub fn replace_in_place(&self, from: Self, to: Self, max_count: Option<usize>) -> Vec<u8> {
800 let len = from.len();

Callers 1

replaceMethod · 0.80

Calls 5

count_substringFunction · 0.85
find_iterMethod · 0.80
as_sliceMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected