marijnh/acorn — pull request #102 by impinball (2014-05-14 02:54:45+00:00)
Title: loop/conditional optimizations

(copied from previous pull request...)

-----

Optimized several conditionals and loops with refactoring. I'm up for any questions (please give line numbers if you spot any issues). There should be few other things changed.

I tried to comment most of my changes.

Also, please pay attention to the comment on line 1778 (relative to my patch): I think I *might* have found a bug, but I'm not entirely sure. I would definitely enjoy some clarification if that is intentional. the reason is because I went to unroll part of the loop to get rid of extra conditionals that would be known right off the bat, but the more optimal equivalent is quite different for each one. I have the suggested fix commented out, but they both are easy to comment out/uncomment.
The original code segments regarding my uncertainty are the `i > 0` in the ternary at line 1745 and the `if (i >= 0)` at line 1748.

I'm considering forking this myself and storing a lot of the true/false information in a bit mask to further enhance speed. I would also make plenty of code style changes, but it would be my own project.

-----

This code has been profiled and it has been found to be equivalent. It also is somewhat faster, as profiled in the V8 engine (tested using the minified release of jQuery 2.1.1, should cover almost all bases/possibilities). Out of 30 reps, it was 73 milliseconds faster. Only the acorn.parse() was actually tested, though.