replaced Box<str> with SmolStr

This commit is contained in:
Moritz Gmeiner 2024-09-02 05:19:30 +02:00
commit da6a820638
21 changed files with 137 additions and 85 deletions

View file

@ -4,6 +4,7 @@ use std::io::{stdin, stdout, Read, Write};
use std::rc::Rc;
use rustc_hash::FxHashMap;
use smol_str::SmolStr;
use crate::error::RuntimeError;
@ -11,7 +12,7 @@ use super::lox_std::init_std;
use super::Value;
pub struct Runtime {
globals: FxHashMap<Box<str>, Value>,
globals: FxHashMap<SmolStr, Value>,
in_stream: Rc<RefCell<dyn std::io::Read>>,
out_stream: Rc<RefCell<dyn std::io::Write>>,
@ -53,7 +54,7 @@ impl Runtime {
self.out_stream.as_ref().borrow_mut()
}
pub fn globals(&self) -> &FxHashMap<Box<str>, Value> {
pub fn globals(&self) -> &FxHashMap<SmolStr, Value> {
&self.globals
}
@ -66,7 +67,7 @@ impl Runtime {
})
}
pub fn define_global(&mut self, name: impl Into<Box<str>>, value: Value) {
pub fn define_global(&mut self, name: impl Into<SmolStr>, value: Value) {
let name = name.into();
self.globals.insert(name, value);
}