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

Method join

crates/vm/src/builtins/str.rs:1155–1173  ·  view source on GitHub ↗
(
        zelf: PyRef<Self>,
        iterable: ArgIterable<PyStrRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

1153
1154 #[pymethod]
1155 fn join(
1156 zelf: PyRef<Self>,
1157 iterable: ArgIterable<PyStrRef>,
1158 vm: &VirtualMachine,
1159 ) -> PyResult<PyStrRef> {
1160 let iter = iterable.iter(vm)?;
1161 let joined = match iter.exactly_one() {
1162 Ok(first) => {
1163 let first = first?;
1164 if first.as_object().class().is(vm.ctx.types.str_type) {
1165 return Ok(first);
1166 } else {
1167 first.as_wtf8().to_owned()
1168 }
1169 }
1170 Err(iter) => zelf.as_wtf8().py_join(iter)?,
1171 };
1172 Ok(vm.ctx.new_str(joined))
1173 }
1174
1175 // FIXME: two traversals of str is expensive
1176 #[inline]

Callers 2

slot_reprMethod · 0.45
reprMethod · 0.45

Calls 8

isMethod · 0.80
py_joinMethod · 0.80
iterMethod · 0.45
classMethod · 0.45
as_objectMethod · 0.45
to_ownedMethod · 0.45
as_wtf8Method · 0.45
new_strMethod · 0.45

Tested by

no test coverage detected