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

Change data structure from Vec to VecDeque #337

Merged
merged 2 commits into from
Jan 5, 2023

Conversation

GreasySlug
Copy link
Member

Fixes #292 .

Stream uses Vec, but, using insert(0), remove(0) in this case, it takes O(n) for this process alone every time

In such cases, it is better to use VecDeque, so as for TokenStream, use the Stream implemented by VecDeque

Changes proposed in this PR:

  • Change Vec to VecDeque
  • Implement Stream with VecDeque
  • TokenStream use VecDeque

@mtshiba

@@ -12,6 +14,128 @@ use crate::consts::{BUILD_DATE, GIT_HASH_SHORT, SEMVER};
use crate::error::{ErrorDisplay, ErrorKind, Location, MultiErrorDisplay};
use crate::{addr_eq, chomp, log, switch_unreachable};

pub trait DequeStream<T>: Sized {
Copy link
Member Author

Choose a reason for hiding this comment

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

I've chosen this name for now, but if something else is better, I'd appreciate suggestions.

@GreasySlug GreasySlug merged commit 993bb13 into erg-lang:main Jan 5, 2023
@GreasySlug GreasySlug deleted the feature/vec_deque branch January 17, 2023 07:13
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

Successfully merging this pull request may close these issues.

TokenStream use VecDeque instead of Vec
1 participant