Skip to content

Commit

Permalink
fixing unfoldSoak performance my memoizing. #1033
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Apr 30, 2011
1 parent 468ad1a commit c516798
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 34 deletions.
49 changes: 28 additions & 21 deletions lib/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 16 additions & 13 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,22 @@ exports.Value = class Value extends Base

# Unfold a soak into an `If`: `a?.b` -> `a.b if a?`
unfoldSoak: (o) ->
if ifn = @base.unfoldSoak o
Array::push.apply ifn.body.properties, @properties
return ifn
for prop, i in @properties when prop.soak
prop.soak = off
fst = new Value @base, @properties.slice 0, i
snd = new Value @base, @properties.slice i
if fst.isComplex()
ref = new Literal o.scope.freeVariable 'ref'
fst = new Parens new Assign ref, fst
snd.base = ref
return new If new Existence(fst), snd, soak: on
null
return @unfoldedSoak if @unfoldedSoak?
result = do =>
if ifn = @base.unfoldSoak o
Array::push.apply ifn.body.properties, @properties
return ifn
for prop, i in @properties when prop.soak
prop.soak = off
fst = new Value @base, @properties.slice 0, i
snd = new Value @base, @properties.slice i
if fst.isComplex()
ref = new Literal o.scope.freeVariable 'ref'
fst = new Parens new Assign ref, fst
snd.base = ref
return new If new Existence(fst), snd, soak: on
null
@unfoldedSoak = result or no

#### Comment

Expand Down

0 comments on commit c516798

Please sign in to comment.