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

Method original_bytes

crates/compiler-core/src/bytecode.rs:788–807  ·  view source on GitHub ↗

Produce a clean copy of the bytecode suitable for serialization (marshal) and `co_code`. Specialized opcodes are mapped back to their base variants via `deoptimize()` and all CACHE entries are zeroed.

(&self)

Source from the content-addressed store, hash-verified

786 /// (marshal) and `co_code`. Specialized opcodes are mapped back to their
787 /// base variants via `deoptimize()` and all CACHE entries are zeroed.
788 pub fn original_bytes(&self) -> Vec<u8> {
789 let len = self.len();
790 let mut out = Vec::with_capacity(len * 2);
791 let mut i = 0;
792 while i < len {
793 let op = self.read_op(i).deoptimize();
794 let arg = self.read_arg(i);
795 let caches = op.cache_entries();
796 out.push(u8::from(op));
797 out.push(u8::from(arg));
798 // Zero-fill all CACHE entries (counter + cached data)
799 for _ in 0..caches {
800 i += 1;
801 out.push(0); // op = Cache = 0
802 out.push(0); // arg = 0
803 }
804 i += 1;
805 }
806 out
807 }
808
809 /// Initialize adaptive warmup counters for all cacheable instructions.
810 /// Called lazily at RESUME (first execution of a code object).

Callers 4

compileMethod · 0.80
cmpMethod · 0.80
co_codeMethod · 0.80
serialize_codeFunction · 0.80

Calls 6

deoptimizeMethod · 0.80
read_opMethod · 0.80
read_argMethod · 0.80
cache_entriesMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected