Skip to content

Commit

Permalink
Big speedup by avoiding calls to Replace on single var definition che…
Browse files Browse the repository at this point in the history
…cks.
  • Loading branch information
corywalker committed Sep 7, 2017
1 parent 279ecf3 commit 19b62fb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions expreduce/evalstate.go
Expand Up @@ -207,6 +207,17 @@ func (this *EvalState) GetDef(name string, lhs Ex) (Ex, bool, *Expression) {
if !this.IsDef(name) {
return nil, false, nil
}
// Special case for checking simple variable definitions like "a = 5".
// TODO: Perhaps split out single var values into the Definition to avoid
// iterating over every one.
if _, lhsIsSym := lhs.(*Symbol); lhsIsSym {
for _, def := range this.defined[name].downvalues {
if _, symDef := def.rule.Parts[1].(*Symbol); symDef {
return def.rule.Parts[2], true, def.rule
}
}
return nil, false, nil
}
this.Debugf("Inside GetDef(\"%s\",%s)", name, lhs)
for i := range this.defined[name].downvalues {
def := this.defined[name].downvalues[i].rule
Expand Down

0 comments on commit 19b62fb

Please sign in to comment.