Skip to content

Commit e2eecf7

Browse files
committed
feat: added a standalone entry key vec to avoid using arbitrary .keys() HashMap function
1 parent 7df65ed commit e2eecf7

4 files changed

Lines changed: 10 additions & 7 deletions

File tree

compiler/compiler_typing/src/enums.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Declarations for enum-kind types.
22
3-
use std::{collections::HashMap};
3+
use std::{collections::HashMap, f32::consts::E};
44

55
use compiler_utils::{hash::{HashedString}, utils::indexed::IndexStorage};
66
use diagnostics::{DiagnosticResult, builders::{make_cannot_find_type_field, make_cannot_find_type_function, make_cannot_find_type_pos, make_enum_parent_fields}};
@@ -114,7 +114,7 @@ impl StructuredType for RawEnumTypeContainer {
114114
}
115115

116116
fn get_functions(&self, _storage: &TypeStorage) -> Vec<u64> {
117-
return self.functions.hash_to_ind.keys().cloned().collect();
117+
return self.functions.entry_keys.clone();
118118
}
119119

120120
fn get_function(&self, hash: u64, _storage: &TypeStorage) -> DiagnosticResult<TypedFunction> {
@@ -156,7 +156,7 @@ impl StructuredType for RawEnumEntryContainer {
156156
}
157157

158158
fn get_fields(&self, _storage: &TypeStorage) -> Vec<u64> {
159-
return self.fields.hash_to_ind.keys().cloned().collect();
159+
return self.fields.entry_keys.clone();
160160
}
161161

162162
fn get_functions(&self, storage: &TypeStorage) -> Vec<u64> {

compiler/compiler_typing/src/structs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ impl StructuredType for RawStructTypeContainer {
7979
}
8080

8181
fn get_fields(&self, _storage: &TypeStorage) -> Vec<u64> {
82-
return self.fields.hash_to_ind.keys().cloned().collect();
82+
return self.fields.entry_keys.clone();
8383
}
8484

8585
fn get_functions(&self, _storage: &TypeStorage) -> Vec<u64> {
86-
return self.functions.hash_to_ind.keys().cloned().collect();
86+
return self.functions.entry_keys.clone();
8787
}
8888

8989
fn get_function_hash(&self, hash: u64, _storage: &TypeStorage) -> DiagnosticResult<usize> {

compiler/compiler_utils/src/utils/indexed.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ use std::collections::HashMap;
55
#[derive(Clone, Debug, PartialEq, Eq)]
66
pub struct IndexStorage<K> {
77
pub hash_to_ind: HashMap<u64, usize>,
8+
pub entry_keys: Vec<u64>,
89
pub vals: Vec<K>
910
}
1011

1112
impl<K> IndexStorage<K> {
1213
pub fn new() -> Self {
13-
return IndexStorage { hash_to_ind: HashMap::new(), vals: vec![] }
14+
return IndexStorage { hash_to_ind: HashMap::new(), vals: vec![], entry_keys: vec![] }
1415
}
1516

1617
pub fn append(&mut self, hash: u64, v: K) -> usize {
1718
let ind = self.vals.len();
1819

20+
self.entry_keys.push(hash);
21+
1922
self.hash_to_ind.insert(hash, ind);
2023
self.vals.push(v);
2124

compiler/llvm_ir_bridge/src/insts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
308308
let t = bridge.types.convert_raw(struct_type).into_struct_type();
309309

310310
let mut vals = vec![];
311-
311+
312312
for value in values {
313313
vals.push(bridge.values[&value.get_ssa_index()].clone().inner);
314314
}

0 commit comments

Comments
 (0)