Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

chore: improve performance for token stream #215

Merged
merged 1 commit into from
Dec 11, 2022
Merged

chore: improve performance for token stream #215

merged 1 commit into from
Dec 11, 2022

Conversation

azjezz
Copy link
Collaborator

@azjezz azjezz commented Dec 11, 2022

before:
image

after:
image

not the best metric to go by, but it shows good improvements :)

Signed-off-by: azjezz <azjezz@protonmail.com>
Comment on lines -90 to +95
pub fn current(&self) -> &Token {
let mut cursor = self.cursor;
loop {
if cursor >= self.length {
return &self.default;
}

let current = &self.tokens[cursor];

if matches!(
current.kind,
TokenKind::SingleLineComment(_)
| TokenKind::MultiLineComment(_)
| TokenKind::HashMarkComment(_)
| TokenKind::DocumentComment(_)
) {
cursor += 1;
continue;
}

return current;
pub const fn current(&self) -> &Token {
if self.cursor >= self.length {
return &self.default;
}

&self.tokens[self.cursor]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to skip comments here, ::new skips comments, and so does next(), so we know that current doesn't refer to a comment.

Comment on lines +117 to +118
let mut cursor = self.cursor + 1;
let mut target = 1;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n is always >= 1, so we can start looking from cursor + 1 instead

@azjezz azjezz merged commit ad4993f into main Dec 11, 2022
@azjezz azjezz deleted the stream-perf branch December 11, 2022 22:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant