Impl Eq+Hash for ConstantData, make CodeInfo.constants an IndexSet

This commit is contained in:
Noah 2021-03-11 09:58:25 -06:00
parent 89c08246ba
commit da0c85d2ac
2 changed files with 5 additions and 6 deletions

View file

@ -157,7 +157,7 @@ impl Compiler {
blocks: vec![ir::Block::default()],
current_block: bytecode::Label(0),
constants: Vec::new(),
constants: IndexSet::default(),
name_cache: IndexSet::default(),
varname_cache: IndexSet::default(),
cellvar_cache: IndexSet::default(),
@ -235,7 +235,7 @@ impl Compiler {
blocks: vec![ir::Block::default()],
current_block: bytecode::Label(0),
constants: Vec::new(),
constants: IndexSet::default(),
name_cache: IndexSet::default(),
varname_cache: IndexSet::default(),
cellvar_cache,
@ -2377,8 +2377,7 @@ impl Compiler {
fn emit_constant(&mut self, constant: ConstantData) {
let info = self.current_codeinfo();
let idx = info.constants.len() as u32;
info.constants.push(constant);
let idx = info.constants.insert_full(constant).0 as u32;
self.emit(Instruction::LoadConst { idx })
}