-
Notifications
You must be signed in to change notification settings - Fork 168
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
Remove unnecessary variable 'state' in LexerImpl by using Stack #450
Conversation
|
@zimmi |
I'm not a maintainer of this repo, just a happy user of pebble. :)
I'd just update this PR, but you might want to wait for one of the maintainers to make the call. |
@zimmi I've checked the javadoc you gave me and it says,
Because ArrayDeque is not thread-safe, and the pebble needs to support complete thread safety, I think it is dangerous to change all the Stack to Deque just because of the performance issue. Anyways, your comment helped me to better understand Java. Thanks :) |
Instances of |
Should you use Deque instead of Stack ? |
This could be debatable. Deque could be better if you're looking at performance, but Stack is better in terms of semantics. Deque can be used like Stack at times, and sometimes like Queue but I think this is a double edged sword. Stack, on the other hand, is just Stack. A Stack cannot be used just like a Queue even if it extends Vector. I think it's a matter of choice but I prefer to use Stack. |
IMHO, no, choice is not debatable: Stack is obsolete and Dequeue’s performance is better. |
Alright then is it okay to close this PR and make another PR to change all the Stack in LexerImpl to Deque? |
Why not edit this one? You just need to update your fork. |
No need to close this PR. Just commit and push to your branch and the PR will bu updated |
It's done. Thanks. |
In my opinion, the 'state' variable in LexerImpl seems unnecessary. You can remove them by using Stack data structure to check the current state. (Replaced LinkedList to Stack to make it clear that the 'states' is managed by Stack)
All the test cases have passed.