-
Notifications
You must be signed in to change notification settings - Fork 13
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
Always check bounds on inserting, no UB necessary fixed #193 #194
base: master
Are you sure you want to change the base?
Conversation
/// it panics only in the "debug" mode. In the "release" mode, you are going to get | ||
/// undefined behavior. This is done for the sake of performance, in order to | ||
/// avoid a repetitive check for the boundary condition on every `insert()`. | ||
/// It may panic if there are too many pairs in the map already. |
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.
@FlareFlo now, since you modified this function, we must introduce another one, as you suggested: insert_undefined
. Otherwise, we simply make this function slower without offering any alternative to the user.
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'm fairly certain that these checks are negligible, unless benchmarks can show otherwise.
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.
@FlareFlo well, it's at least two CPU instructions. They can't be negligible :)
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.
@FlareFlo well, it's at least two CPU instructions. They can't be negligible :)
The branch predictor and prefetcher will most likely disagree.
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.
@FlareFlo yes, most likely, but why should we take a chance? The ultimate objective of this library is to be the fastest possible. Not the most convenient, not the most user-friendly, but the fastest. Every CPU tick counts :)
No description provided.