-
Notifications
You must be signed in to change notification settings - Fork 34
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
Refactor Stack utility class #495
Conversation
@chfast I'm in favour of this, what is blocking here? Is the goal just cleanup or some speed benefit for parsing? |
Nothing is blocking this, but unit tests must be updated. See updated description. |
I'd prefer this PR, unless there is some significant parser slowdown. |
117c18b
to
ed42f15
Compare
EXPECT_EQ(stack.size(), 0); | ||
} | ||
|
||
TEST(stack, resize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no test for shrink
besides this.
Could rename the |
Codecov Report
@@ Coverage Diff @@
## master #495 +/- ##
==========================================
- Coverage 99.69% 99.69% -0.01%
==========================================
Files 54 54
Lines 17180 17091 -89
==========================================
- Hits 17128 17039 -89
Misses 52 52 |
lib/fizzy/stack.hpp
Outdated
} | ||
|
||
/// Drops @a num_elements elements from the top of the stack. | ||
void drop(size_t num_elements = 1) noexcept { shrink(size() - num_elements); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, shouldn't this need assert(size() >= num_elements)
, since size_t
is unsigned, the value to shrink
could wrap around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OperandStack::drop
has assert(num_elements <= size())
so maybe follow that style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed drop().
The rest looks good to me. Does this result in any significant regression in parsing? |
Not really a change performance-wise
|
} | ||
|
||
T pop() | ||
T pop() noexcept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this marked noexcept because we manually ensure the caller will call it in a bad state? (Enforced by the assert in debug mode) Note that back
and pop_back
are not noexcept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert is not relevant. This is noexcept
because .back()
and .pop_back()
are noexcept
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked it when I commented on empty/size, but to me back/pop_back did not seem to be noexcept:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay noexcept since C++20:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were these behaving as noexcept pre-C++20 just not marked so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Officially they are not noexcept
(even in C++20), but in practice they are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay to me, but would prefer a second look from @gumb0 on the noexcept question.
I started this to investigate "containter-overflow" issues reported by ASan in XCode 12.0 beta. This does not fix the issue, but at least I minimized the Stack interface and we don't use inheritance any more.