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

Method emit_pending_fstring_literal

crates/codegen/src/compile.rs:10031–10050  ·  view source on GitHub ↗
(
        &mut self,
        pending_literal: &mut Option<Wtf8Buf>,
        element_count: &mut u32,
        keep_empty: bool,
    )

Source from the content-addressed store, hash-verified

10029 }
10030
10031 fn emit_pending_fstring_literal(
10032 &mut self,
10033 pending_literal: &mut Option<Wtf8Buf>,
10034 element_count: &mut u32,
10035 keep_empty: bool,
10036 ) {
10037 let Some(value) = pending_literal.take() else {
10038 return;
10039 };
10040
10041 // CPython drops empty literal fragments when they are adjacent to
10042 // formatted values, but still emits an empty string for a fully-empty
10043 // f-string.
10044 if value.is_empty() && (!keep_empty || *element_count > 0) {
10045 return;
10046 }
10047
10048 self.emit_load_const(ConstantData::Str { value });
10049 *element_count += 1;
10050 }
10051
10052 /// Optimize `'format_str' % (args,)` into f-string bytecode.
10053 /// Returns true if optimization was applied, false to fall back to normal BINARY_OP %.

Callers 2

finish_fstringMethod · 0.80

Calls 3

emit_load_constMethod · 0.80
takeMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected