Skip to main content

luaur_bytecode/methods/
bytecode_builder_table_shape_hash_operator_call.rs

1use crate::records::table_shape::TableShape;
2use crate::records::table_shape_hash::TableShapeHash;
3
4impl TableShapeHash {
5    #[allow(non_snake_case)]
6    pub fn operator_call(&self, v: &TableShape) -> usize {
7        // FNV-1a inspired hash (note that we feed integers instead of bytes)
8        let mut hash: u32 = 2166136261;
9
10        for i in 0..(v.length as usize) {
11            hash ^= v.keys[i] as u32;
12            hash = hash.wrapping_mul(16777619);
13
14            // Note: FFlag::LuauCompileDuptableConstantPack2 is assumed true in this translation context
15            // as we are translating the logic that depends on the shape's internal state.
16            if v.hasConstants {
17                hash ^= v.constants[i] as u32;
18                hash = hash.wrapping_mul(16777619);
19            }
20        }
21
22        hash as usize
23    }
24}