Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize single-item productions #1

Open
felipeochoa opened this issue Mar 26, 2018 · 0 comments
Open

Optimize single-item productions #1

felipeochoa opened this issue Mar 26, 2018 · 0 comments

Comments

@felipeochoa
Copy link
Owner

A bunch of generic sequence code could be removed for single-item productions. E.g., (+ "x") expands to:

(mole-parse-match
    (children
     (mole-parse-match
         (res
          (let (item star-items)
            (while (mole-parse-success-p
                 (setq item
                       (mole-parse-match (res (mole-parse-anonymous-literal "x" nil)) ;; (1)
                         (list res)
                         'fail)))
              (setq star-items (nconc star-items item)))
            (if star-items
                (mole-node '+ star-items nil)
              'fail)))
       (list res)
       'fail))
  (mole-node 'mole~x children nil)
  'fail)

This optimization would get rid of the mole-parse-match in (1) and convert the (while ... (nconc...)) loop into a more idiomatic (and probably faster) (progn (while ... (push ...)) (nreverse ...)))

@felipeochoa felipeochoa changed the title Optimization: single-item productions Optimize single-item productions Mar 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant