Browse Source

Store field metadata in an Arc instead

Ben Simms 1 year ago
parent
commit
a9973b32c2
2 changed files with 6 additions and 3 deletions
  1. 3 1
      numbat/src/value.rs
  2. 3 2
      numbat/src/vm.rs

+ 3 - 1
numbat/src/value.rs

@@ -1,3 +1,5 @@
+use std::sync::Arc;
+
 use itertools::Itertools;
 
 use crate::{pretty_print::PrettyPrint, quantity::Quantity};
@@ -31,7 +33,7 @@ pub enum Value {
     DateTime(chrono::DateTime<chrono::FixedOffset>),
     FunctionReference(FunctionReference),
     FormatSpecifiers(Option<String>),
-    Struct(Vec<(String, usize)>, Vec<Value>),
+    Struct(Arc<[(String, usize)]>, Vec<Value>),
 }
 
 impl Value {

+ 3 - 2
numbat/src/vm.rs

@@ -1,4 +1,5 @@
 use std::collections::HashMap;
+use std::sync::Arc;
 use std::{cmp::Ordering, fmt::Display};
 
 use indexmap::IndexSet;
@@ -279,7 +280,7 @@ pub struct Vm {
     pub constants: Vec<Constant>,
 
     /// struct field metadata, used so we can recover struct field layout at runtime
-    struct_fields: IndexSet<Vec<(String, usize)>>,
+    struct_fields: IndexSet<Arc<[(String, usize)]>>,
 
     /// Unit prefixes in use
     prefixes: Vec<Prefix>,
@@ -380,7 +381,7 @@ impl Vm {
     }
 
     pub fn add_struct_fields(&mut self, fields: Vec<(String, usize)>) -> u16 {
-        let (idx, _) = self.struct_fields.insert_full(fields);
+        let (idx, _) = self.struct_fields.insert_full(fields.into());
 
         idx as u16
     }