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

Parse in boundaries #13

Closed
volrath opened this issue Dec 10, 2017 · 5 comments
Closed

Parse in boundaries #13

volrath opened this issue Dec 10, 2017 · 5 comments

Comments

@volrath
Copy link
Member

volrath commented Dec 10, 2017

I'm currently in the need of parsing just a fraction of a buffer, so I thought on changing the signature of parseclj-parse-clojure to something like:

(defun parseclj-parse-clojure (&optional bounds-or-string options)
  ...)

bounds-or-string can be either a list (or cons) with positions/markers, a string that will be put into a temp buffer and scanned from (point-min) to (point-max), or nil, in which case just scans from (point) til the end (current default behavior)

I wanted to hear your thoughts on it before implementing.

My temporary solution is to use narrowing:

(save-excursion
  (goto-char (car bounds))
  (apply #'narrow-to-region bounds)
  (prog1 (parseclj-parse-clojure)
    (widen)))

But I think it's not ideal.

@lambdaisland
Copy link

lambdaisland commented Dec 10, 2017 via email

@volrath
Copy link
Member Author

volrath commented Dec 10, 2017

Basically the save-excursion. I've read it's costly in terms of performance, and since we're going for high performance here...

On the other hand I also get that we'd need to also change parseclj-parser signature to get the boundaries so that the shift-reduce process would stop at either :eof or (cdr bounds), which also mean tweak with parseedn...

@plexus
Copy link
Collaborator

plexus commented Dec 10, 2017

What do you think of doing some benchmarks on this? I can see the need for this behavior, but it'll add a good bit of complexity, so it would be good to know it'll be worth it...

Things we could compare to get a base line:

  • current behavior of just scanning a buffer until the end
  • use save-excursion and narrow-to-region
  • use buffer-substring (or buffer-substring-no-properties, I'm not sure which one is actually faster), and pass that to the parser (which then creates a temp buffer).

If the second two are really a lot slower than the first one, then it's worth it to change the API. In that case I would prefer making it two options, :start which defaults to (point), and :end which defaults to (point-max). I like that better than having to pass in an extra nil just to get the base behaviour.

@volrath
Copy link
Member Author

volrath commented Dec 10, 2017

Both things (benchmarking and using :start/:end options) sound good to me :)

@MalloZup
Copy link

MalloZup commented Aug 5, 2019

autogenerated with https://github.com/MalloZup/doghub: issue inactive since 450 days. Please update the issue or close it

@plexus plexus closed this as completed Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants