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

zero-saturating size sub #1586

Merged
merged 2 commits into from
Nov 21, 2024
Merged

Conversation

m4rch3n1ng
Copy link
Contributor

@m4rch3n1ng m4rch3n1ng commented Nov 14, 2024

this pr is two commits

  • in [b5b9410] i impl Sub for Size, that just mirrors what the SubAssign already does

  • [ecb3f85] might be a little controvertial: Sub and SubAssign operations on Size are already saturating, but they saturate to i32::MIN, which i don't personally think is very useful, because a Size can (should) not be negative, which means that i always have to check before subtracting two sizes. i changed it so they saturate to 0.

to saturate to 0, i added an assossiated const ZERO: Self to the Coordinate trait.

if you prefer, i could move them to a Size::saturating_sub(other: Size) instead, but i think that this change makes Size more convenient to use.

Copy link
Member

@Drakulix Drakulix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find any reason against this, given we already had the debug_assert.

@cmeissl @ids1024 @PolyMeilex @i509VCB if there aren't any complains in the next couple of days, I am going to merge this.

Copy link
Collaborator

@cmeissl cmeissl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Drakulix Drakulix merged commit b829240 into Smithay:master Nov 21, 2024
13 checks passed
@Drakulix
Copy link
Member

Thanks @m4rch3n1ng!

@m4rch3n1ng m4rch3n1ng deleted the zero-saturating-size-sub branch November 21, 2024 13:45
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.

3 participants