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

Always check bounds on inserting, no UB necessary fixed #193 #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FlareFlo
Copy link

No description provided.

/// 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.
Copy link
Owner

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.

Copy link
Author

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.

Copy link
Owner

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 :)

Copy link
Author

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.

Copy link
Owner

@yegor256 yegor256 May 22, 2024

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 :)

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.

None yet

2 participants