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

add getTokensBefore and getTokensAfter interface for efficient token lookup #735

Closed
michaelficarra opened this issue Mar 29, 2014 · 4 comments

Comments

Projects
None yet
3 participants
@michaelficarra
Copy link
Member

commented Mar 29, 2014

From #574 (comment):

The API for getTokens could probably use a redesign. Right now you ask for the tokens for a node including n tokens before the node and m tokens after. This is often misused in rules that are just looking for the preceding n or following m tokens. If we expose that functionality individually, we can probably eliminate most of these requests for huge portions of the token stream.

This should dramatically improve performance of the rules that use getTokens in this way.

@nzakas

This comment has been minimized.

Copy link
Member

commented Mar 29, 2014

Totally. From looking at the rules, it seems like the common use cases are:

  • get first token
  • get last token
  • get next token
  • get next two tokens
  • get previous token

I'm not sure if we need separate methods for each of these, but it would be nice to cover all the existing cases.

@nzakas nzakas added core labels Mar 29, 2014

@michaelficarra

This comment has been minimized.

Copy link
Member Author

commented Mar 30, 2014

Working on this.

michaelficarra added a commit to michaelficarra/eslint that referenced this issue Mar 30, 2014

michaelficarra added a commit to michaelficarra/eslint that referenced this issue Mar 30, 2014

michaelficarra added a commit to michaelficarra/eslint that referenced this issue Mar 30, 2014

michaelficarra added a commit to michaelficarra/eslint that referenced this issue Mar 30, 2014

michaelficarra added a commit to michaelficarra/eslint that referenced this issue Mar 31, 2014

michaelficarra added a commit to michaelficarra/eslint that referenced this issue Mar 31, 2014

michaelficarra added a commit to michaelficarra/eslint that referenced this issue Mar 31, 2014

michaelficarra added a commit to michaelficarra/eslint that referenced this issue Mar 31, 2014

michaelficarra added a commit to michaelficarra/eslint that referenced this issue Apr 1, 2014

fixes eslint#735: add new, more efficient getTokens interfaces
This is a combination of 6 commits.
The first commit's message is:

add getTokensBefore and getTokensAfter interfaces (ref eslint#735)

This is the 2nd commit message:

add getTokenBefore and getTokenAfter interfaces (ref eslint#735)

This is the 3rd commit message:

add getFirstTokens and getLastTokens interfaces (ref eslint#735)

This is the 4th commit message:

add getFirstToken and getLastToken interfaces (ref eslint#735)

This is the 5th commit message:

expose new getTokens methods to rule context object

This is the 6th commit message:

make use of new getTokens methods in rules

@nzakas nzakas closed this in #738 Apr 1, 2014

nzakas added a commit that referenced this issue Apr 1, 2014

Merge pull request #738 from michaelficarra/GH-735
fixes #735: add getTokensBefore, getTokensAfter, getTokensFirst, and getTokensLast interfaces
@ariya

This comment has been minimized.

Copy link

commented Apr 3, 2014

What about findOpenParen(tokens) in no-spaced-func? Is there a chance that it could use the node's arguments instead of walking through all the tokens?

@michaelficarra

This comment has been minimized.

Copy link
Member Author

commented Apr 3, 2014

Yeah, probably. I doubt that's affecting performance much, but it could certainly be done more efficiently.

@eslint eslint bot locked and limited conversation to collaborators Feb 7, 2018

@eslint eslint bot added the archived due to age label Feb 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.