3 ms·
I was surprised by the difference between the Simple and Chain results. Naively, I had thought they'd generate the same byte code.
by js2 10y ago
I was surprised by the difference between the Simple and Chain results. Naively, I had thought they'd generate the same byte code.
- kodablah 10y agoThe main deal is that an instance method (e.g. append) uses the latest stack value as the instance and has its return value put on the stack. So when chaining, it doesn't need to re-put the variable on the stack to call the next method. When not chaining, it has to pop (i.e. discard) that previous return value and then re-put the builder/buffer variable on the stack each time. But this is seriously micro-opimtization only beneficial in the most strict of situations. Only in this crazy situations would I ever use this as justification to choose one approach over the other.