mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 04:12:42 +00:00
replaced Box<str> with SmolStr
This commit is contained in:
parent
fb88595b6c
commit
da6a820638
21 changed files with 137 additions and 85 deletions
|
|
@ -2,6 +2,7 @@ use std::fmt::{Debug, Display};
|
|||
use std::rc::Rc;
|
||||
|
||||
use rlox2_frontend::parser::Stmt;
|
||||
use smol_str::SmolStr;
|
||||
|
||||
use crate::environment::{ClosureScope, HeapedValue};
|
||||
|
||||
|
|
@ -11,17 +12,17 @@ use super::{Runtime, Value};
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LoxFunction {
|
||||
name: Box<str>,
|
||||
name: SmolStr,
|
||||
closure: ClosureScope,
|
||||
param_names: Vec<Box<str>>,
|
||||
param_names: Vec<SmolStr>,
|
||||
body: Box<Stmt>,
|
||||
}
|
||||
|
||||
impl LoxFunction {
|
||||
pub fn new(
|
||||
name: impl Into<Box<str>>,
|
||||
name: impl Into<SmolStr>,
|
||||
closure: ClosureScope,
|
||||
param_names: Vec<Box<str>>,
|
||||
param_names: Vec<SmolStr>,
|
||||
body: Stmt,
|
||||
) -> Rc<Self> {
|
||||
let name = name.into();
|
||||
|
|
@ -43,7 +44,7 @@ impl LoxFunction {
|
|||
&self.closure
|
||||
}
|
||||
|
||||
pub fn param_names(&self) -> &[Box<str>] {
|
||||
pub fn param_names(&self) -> &[SmolStr] {
|
||||
&self.param_names
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +56,7 @@ impl LoxFunction {
|
|||
self.param_names().len()
|
||||
}
|
||||
|
||||
pub fn inject_closed_var(&mut self, name: impl Into<Box<str>>, value: Value) {
|
||||
pub fn inject_closed_var(&mut self, name: impl Into<SmolStr>, value: Value) {
|
||||
let name = name.into();
|
||||
let heaped_value = HeapedValue::new(value);
|
||||
self.closure.insert(name, heaped_value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue