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

Method concat_in_place

crates/vm/src/builtins/str.rs:1501–1521  ·  view source on GitHub ↗
(&mut self, other: &Wtf8, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1499 }
1500
1501 pub fn concat_in_place(&mut self, other: &Wtf8, vm: &VirtualMachine) {
1502 if other.is_empty() {
1503 return;
1504 }
1505 let mut s = Wtf8Buf::with_capacity(self.byte_len() + other.len());
1506 s.push_wtf8(self.as_ref());
1507 s.push_wtf8(other);
1508 if self.as_object().strong_count() == 1 {
1509 // SAFETY: strong_count()==1 guarantees unique ownership of this PyStr.
1510 // Mutating payload in place preserves semantics while avoiding PyObject reallocation.
1511 unsafe {
1512 let payload = self.payload() as *const PyStr as *mut PyStr;
1513 (*payload).data = PyStr::from(s).data;
1514 (*payload)
1515 .hash
1516 .store(hash::SENTINEL, atomic::Ordering::Relaxed);
1517 }
1518 } else {
1519 *self = PyStr::from(s).into_ref(&vm.ctx);
1520 }
1521 }
1522
1523 pub fn try_into_utf8(self, vm: &VirtualMachine) -> PyResult<PyRef<PyUtf8Str>> {
1524 self.ensure_valid_utf8(vm)?;

Callers 2

execute_instructionMethod · 0.80
readlineMethod · 0.80

Calls 10

push_wtf8Method · 0.80
strong_countMethod · 0.80
payloadMethod · 0.80
is_emptyMethod · 0.45
byte_lenMethod · 0.45
lenMethod · 0.45
as_refMethod · 0.45
as_objectMethod · 0.45
storeMethod · 0.45
into_refMethod · 0.45

Tested by

no test coverage detected