diff --git a/src/compile.rs b/src/compile.rs index e25bd7c..3dfd773 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -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 }) } diff --git a/src/ir.rs b/src/ir.rs index 89cecc8..d2926bf 100644 --- a/src/ir.rs +++ b/src/ir.rs @@ -37,7 +37,7 @@ pub struct CodeInfo { pub blocks: Vec, pub current_block: BlockIdx, - pub constants: Vec, + pub constants: IndexSet, pub name_cache: IndexSet, pub varname_cache: IndexSet, pub cellvar_cache: IndexSet, @@ -104,7 +104,7 @@ impl CodeInfo { max_stacksize, instructions: instructions.into_boxed_slice(), locations: locations.into_boxed_slice(), - constants: constants.into(), + constants: constants.into_iter().collect(), names: name_cache.into_iter().collect(), varnames: varname_cache.into_iter().collect(), cellvars: cellvar_cache.into_iter().collect(),