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

Remove unnecessary check from size_bytes() #1105

Merged

Conversation

dmitrykobets-msft
Copy link
Member

size_bytes() returns the span's size in bytes.
Assuming the span was constructed with an accurate size parameter, the check size() < dynamic_extent / sizeof(element_type) isn't required, since size_t(-1) (which is dynamic_extent) represents the size of the address space, so the number of bytes will never exceed it and in practice won't even come close.
Otherwise, it is not actually feasible to detect cases when the size parameter does not correspond to the dimensions of the underlying data pointer. In these cases, the relationship size() < dynamic_extent / sizeof(element_type) is simply one of many ways in which the size() could be incorrect, and serves no necessary purpose.

Resolves #1012

@dmitrykobets-msft dmitrykobets-msft merged commit 9face82 into microsoft:main May 9, 2023
66 checks passed
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.

size_bytes unnecessarily optimizes poorly
1 participant