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

Method optimize_load_global_push_null

crates/codegen/src/ir.rs:1428–1452  ·  view source on GitHub ↗

LOAD_GLOBAL + PUSH_NULL -> LOAD_GLOBAL , NOP

(&mut self)

Source from the content-addressed store, hash-verified

1426
1427 /// LOAD_GLOBAL <even> + PUSH_NULL -> LOAD_GLOBAL <odd>, NOP
1428 fn optimize_load_global_push_null(&mut self) {
1429 for block in &mut self.blocks {
1430 let mut i = 0;
1431 while i + 1 < block.instructions.len() {
1432 let curr = &block.instructions[i];
1433 let next = &block.instructions[i + 1];
1434
1435 let (Some(Instruction::LoadGlobal { .. }), Some(Instruction::PushNull)) =
1436 (curr.instr.real(), next.instr.real())
1437 else {
1438 i += 1;
1439 continue;
1440 };
1441
1442 let oparg = u32::from(block.instructions[i].arg);
1443 if (oparg & 1) != 0 {
1444 i += 1;
1445 continue;
1446 }
1447
1448 block.instructions[i].arg = OpArg::new(oparg | 1);
1449 block.instructions.remove(i + 1);
1450 }
1451 }
1452 }
1453
1454 /// Convert LOAD_CONST for small integers to LOAD_SMALL_INT
1455 /// maybe_instr_make_load_smallint

Callers 1

finalize_codeMethod · 0.80

Calls 4

newFunction · 0.85
lenMethod · 0.45
realMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected