LiveScript icon indicating copy to clipboard operation
LiveScript copied to clipboard

Destructure assignment optimization

Open determin1st opened this issue 5 years ago • 2 comments

For example, this expression:

{item1, item2} = o = new CustomObject!

compiles to this code:

ref$ = o = new CustomObject(), item1 = ref$.item1, item2 = ref$.item2;

but could be:

o = new CustomObject(), item1 = o.item1, item2 = o.item2;

as the new object is already assigned to o, additional reference variable is not needed. do you agree?

determin1st avatar Oct 26 '18 09:10 determin1st

Yes, I think I do agree. We'll have to be careful, though, about cases like

{a: o, b} = o = f!

which still require the ref$ variable.

rhendric avatar Oct 26 '18 18:10 rhendric

I'll be careful, i promise :]

determin1st avatar Oct 27 '18 07:10 determin1st