Remove some unnecessary destructurings of Rc<String>

This commit is contained in:
greg 2017-01-04 16:56:17 -08:00
parent 328ec4ba87
commit e888e82404

View File

@ -9,7 +9,7 @@ type Reduction<T> = (T, Option<SideEffect>);
#[derive(Debug)] #[derive(Debug)]
enum SideEffect { enum SideEffect {
Print(String), Print(String),
AddBinding(String, Expression), AddBinding(Rc<String>, Expression),
AddFunctionBinding(Function), AddFunctionBinding(Function),
} }
@ -52,8 +52,8 @@ impl<'a> Evaluator<'a> {
self.functions.insert(name, function); self.functions.insert(name, function);
} }
fn lookup_function(&self, name: String) -> Option<Function> { fn lookup_function(&self, name: &str) -> Option<Function> {
match self.functions.get(&name) { match self.functions.get(name) {
Some(func) => Some(func.clone()), Some(func) => Some(func.clone()),
None => match self.parent { None => match self.parent {
Some(env) => env.lookup_function(name), Some(env) => env.lookup_function(name),
@ -126,7 +126,7 @@ impl<'a> Evaluator<'a> {
match side_effect { match side_effect {
Print(s) => println!("{}", s), Print(s) => println!("{}", s),
AddBinding(var, value) => { AddBinding(var, value) => {
self.add_binding(var, value); self.add_binding((*var).clone(), value);
}, },
AddFunctionBinding(function) => { AddFunctionBinding(function) => {
self.add_function((*function.prototype.name).clone(), function); self.add_function((*function.prototype.name).clone(), function);
@ -175,7 +175,7 @@ impl<'a> Evaluator<'a> {
if *op == "=" { if *op == "=" {
match left { match left {
Variable(var) => { Variable(var) => {
let binding = SideEffect::AddBinding((*var).clone(), right); let binding = SideEffect::AddBinding(var, right);
return (Null, Some(binding)); return (Null, Some(binding));
} }
_ => return (Null, None), _ => return (Null, None),
@ -275,12 +275,12 @@ impl<'a> Evaluator<'a> {
if *name == "print" { if *name == "print" {
let mut s = String::new(); let mut s = String::new();
for arg in arguments { for arg in arguments {
s.push_str(&format!("{}\n", arg)); s.push_str(&format!("{} ", arg));
} }
return (Null, Some(SideEffect::Print(s))); return (Null, Some(SideEffect::Print(s)));
} }
let function = match self.lookup_function((*name).clone()) { let function = match self.lookup_function(&*name) {
Some(func) => func, Some(func) => func,
None => return (Null, None), None => return (Null, None),
}; };