an-cabal/an-rope

Replace or_zero macro with saturating_sub

Closed this issue · 2 comments

hawkw commented

There are a number of places where we use a macro, or_zero!, to subtract two unsigned numbers and return zero rather than overflowing if the result is less than zero. This is the same behaviour as the saturating_sub() function in the standard library.

It'd be nice if instances of this macro could be replaced with saturating_sub(), as this is more idiomatic and might be faster on some platforms (if the CPU has a saturating subtraction operation, it could use an intrinsic...).

Once all uses of or_zero! are replaced, the macro definition can also be removed.

hawkw commented

This is probably pretty easy to fix, and reasonably low-priority. @rachlmac, if you want it, I'm happy to save this issue for you?

Hope I'm not stepping on toes, but I noticed it had been 13 days, so I thought I would give it a go. Please let me know if you find any issues with how I have done this code or PR! Thanks!