juliangruber / balanced-match

Match balanced character pairs, like { and }
MIT License
125 stars 40 forks source link

Optimisations #7

Closed neytema closed 8 years ago

neytema commented 8 years ago

Optimised code by using indexOf to find matches and array backtracking instead of recursive calls for leftover cases.

Additionally search logic is separated from resulting object formation to simplify things (new API method as a side effect).

Simple benchmark shows that code runs more than 2x faster in most cases.

juliangruber commented 8 years ago

impressive! lgtm, @isaacs?

isaacs commented 8 years ago

I'd like a chance to test this in the context of mini match and glob to make sure there are no surprising changes to behavior in a relevant edge case. But yes, impressive as heck!

I'll probably get a chance to review tomorrow. Holiday here in the USA :)

neytema commented 8 years ago

Sorry, I wrote code against tests and missed one case.

I thought that something smells fishy, backtracking code was to simple :)

isaacs commented 8 years ago

Just tested with glob and minimatch. Seems good to me!

Definitely bump the minor version, since a new API method was added.

juliangruber commented 8 years ago

thank you @neytema for the implementation and @isaacs for the review, published as 0.3.0