mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-25 05:54:32 +00:00
Impl Eq+Hash for ConstantData, make CodeInfo.constants an IndexSet
This commit is contained in:
parent
89c08246ba
commit
da0c85d2ac
2 changed files with 5 additions and 6 deletions
|
@ -157,7 +157,7 @@ impl Compiler {
|
||||||
|
|
||||||
blocks: vec![ir::Block::default()],
|
blocks: vec![ir::Block::default()],
|
||||||
current_block: bytecode::Label(0),
|
current_block: bytecode::Label(0),
|
||||||
constants: Vec::new(),
|
constants: IndexSet::default(),
|
||||||
name_cache: IndexSet::default(),
|
name_cache: IndexSet::default(),
|
||||||
varname_cache: IndexSet::default(),
|
varname_cache: IndexSet::default(),
|
||||||
cellvar_cache: IndexSet::default(),
|
cellvar_cache: IndexSet::default(),
|
||||||
|
@ -235,7 +235,7 @@ impl Compiler {
|
||||||
|
|
||||||
blocks: vec![ir::Block::default()],
|
blocks: vec![ir::Block::default()],
|
||||||
current_block: bytecode::Label(0),
|
current_block: bytecode::Label(0),
|
||||||
constants: Vec::new(),
|
constants: IndexSet::default(),
|
||||||
name_cache: IndexSet::default(),
|
name_cache: IndexSet::default(),
|
||||||
varname_cache: IndexSet::default(),
|
varname_cache: IndexSet::default(),
|
||||||
cellvar_cache,
|
cellvar_cache,
|
||||||
|
@ -2377,8 +2377,7 @@ impl Compiler {
|
||||||
|
|
||||||
fn emit_constant(&mut self, constant: ConstantData) {
|
fn emit_constant(&mut self, constant: ConstantData) {
|
||||||
let info = self.current_codeinfo();
|
let info = self.current_codeinfo();
|
||||||
let idx = info.constants.len() as u32;
|
let idx = info.constants.insert_full(constant).0 as u32;
|
||||||
info.constants.push(constant);
|
|
||||||
self.emit(Instruction::LoadConst { idx })
|
self.emit(Instruction::LoadConst { idx })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub struct CodeInfo {
|
||||||
|
|
||||||
pub blocks: Vec<Block>,
|
pub blocks: Vec<Block>,
|
||||||
pub current_block: BlockIdx,
|
pub current_block: BlockIdx,
|
||||||
pub constants: Vec<ConstantData>,
|
pub constants: IndexSet<ConstantData>,
|
||||||
pub name_cache: IndexSet<String>,
|
pub name_cache: IndexSet<String>,
|
||||||
pub varname_cache: IndexSet<String>,
|
pub varname_cache: IndexSet<String>,
|
||||||
pub cellvar_cache: IndexSet<String>,
|
pub cellvar_cache: IndexSet<String>,
|
||||||
|
@ -104,7 +104,7 @@ impl CodeInfo {
|
||||||
max_stacksize,
|
max_stacksize,
|
||||||
instructions: instructions.into_boxed_slice(),
|
instructions: instructions.into_boxed_slice(),
|
||||||
locations: locations.into_boxed_slice(),
|
locations: locations.into_boxed_slice(),
|
||||||
constants: constants.into(),
|
constants: constants.into_iter().collect(),
|
||||||
names: name_cache.into_iter().collect(),
|
names: name_cache.into_iter().collect(),
|
||||||
varnames: varname_cache.into_iter().collect(),
|
varnames: varname_cache.into_iter().collect(),
|
||||||
cellvars: cellvar_cache.into_iter().collect(),
|
cellvars: cellvar_cache.into_iter().collect(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue