Performance improvements (#15)

* Performance improvements

Two main changes:

1. Cache parsed AST in a Source. So Parser will parse content only once.
2. Use one unified visitor with multiple callbacks instead of multiple
visitors to traverse AST.

This improves performance significantly, for example running it on
Crystal repository takes ~1 second, which 6 times faster than before.

* Change readme example
This commit is contained in:
V. Elenhaupt 2017-11-06 20:54:58 +02:00 committed by GitHub
parent f27e32cbea
commit adfe654733
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 34 additions and 42 deletions

View file

@ -8,7 +8,7 @@ module Ameba::AST
{% for name in NODE_VISITORS %}
describe "{{name}}" do
it "allow to visit {{name}} node" do
visitor = {{name}}Visitor.new rule, source
visitor = Visitor.new rule, source
nodes = Crystal::Parser.new("").parse
nodes.accept visitor
end