Commit b515add
committed
Use macro for wrapping += and -=
The current auto-generated += and -= implementation is hard to read, and should be replaced with += where possible. That said, we cannot auto-replace it just yet because Rust behaves differently in debug mode, therefore we should use second best approach - a macro that clearly shows intention without all the boilerplate code.
The only manual code are two macros in the src/enc/mod.rs
Use this replacement file as described in other recent PRs to replace boilerplate code.
<details>
<summary>replacement file content</summary>
```diff
@@
expression cond, expr;
@@
if cond
{
- let _rhs = 1;
- let _lhs = &mut expr;
- *_lhs = (*_lhs).wrapping_add(_rhs as u32);
+::wrapping_add!(expr, 1);
}
@@
expression expr;
@@
-{
- let _rhs = 1;
- let _lhs = &mut expr;
- *_lhs = (*_lhs).wrapping_add(_rhs as u32);
+::wrapping_add!(expr, 1);
-}
@@
expression expr;
@@
-{
- let _rhs = 1u32;
- let _lhs = &mut expr;
- *_lhs = (*_lhs).wrapping_add(_rhs);
+::wrapping_add!(expr, 1);
-}
@@
expression expr;
@@
-{
- let _rhs = 1i32;
- let _lhs = &mut expr;
- *_lhs = (*_lhs).wrapping_add(_rhs as u32);
+::wrapping_add!(expr, 1);
-}
@@
expression expr;
@@
-{
- let _rhs = 1;
- let _lhs = &mut expr;
- *_lhs = (*_lhs).wrapping_add(_rhs as usize);
+::wrapping_add!(expr, 1);
-}
@@
expression inc, expr;
@@
-{
- let _rhs = inc;
- let _lhs = &mut expr;
- *_lhs = (*_lhs).wrapping_add(_rhs as u32);
+::wrapping_add!(expr, inc as u32);
-}
@@
expression inc, expr;
@@
-{
- let _rhs = inc;
- let _lhs = &mut expr;
- *_lhs = (*_lhs).wrapping_add(_rhs);
+::wrapping_add!(expr, inc);
-}
@@
expression inc, expr;
@@
-{
- let _rhs = inc;
- let _lhs = &mut expr;
- *_lhs = (*_lhs).wrapping_add(_rhs as u32);
+::wrapping_add!(expr, inc as u32);
-}
@@
expression inc, expr;
@@
-{
- let _rhs = inc;
- let _lhs = &mut expr;
- *_lhs = (*_lhs).wrapping_add(_rhs as usize);
+::wrapping_add!(expr, inc as usize);
-}
@@
expression expr;
@@
-{
- let _rhs = 1;
- let _lhs = &mut expr;
- *_lhs = (*_lhs).wrapping_sub(_rhs as usize);
+::wrapping_sub!(expr, 1);
-}
```
</details>1 parent c35494b commit b515add
File tree
5 files changed
+29
-25
lines changed- src/enc
5 files changed
+29
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
| 451 | + | |
456 | 452 | | |
457 | 453 | | |
458 | 454 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
179 | 178 | | |
180 | 179 | | |
181 | 180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1737 | 1737 | | |
1738 | 1738 | | |
1739 | 1739 | | |
1740 | | - | |
1741 | | - | |
1742 | | - | |
1743 | | - | |
1744 | | - | |
1745 | | - | |
1746 | | - | |
1747 | | - | |
1748 | | - | |
1749 | | - | |
| 1740 | + | |
| 1741 | + | |
1750 | 1742 | | |
1751 | 1743 | | |
1752 | 1744 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
630 | 630 | | |
631 | 631 | | |
632 | 632 | | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
638 | 637 | | |
639 | 638 | | |
640 | 639 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
0 commit comments