Commit aa523c9
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 6fae4d3 commit aa523c9
4 files changed
+12
-30
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
508 | 508 | | |
509 | 509 | | |
510 | 510 | | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
| 511 | + | |
516 | 512 | | |
517 | 513 | | |
518 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
189 | 188 | | |
190 | 189 | | |
191 | 190 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1397 | 1397 | | |
1398 | 1398 | | |
1399 | 1399 | | |
1400 | | - | |
1401 | | - | |
1402 | | - | |
1403 | | - | |
1404 | | - | |
| 1400 | + | |
1405 | 1401 | | |
1406 | 1402 | | |
1407 | 1403 | | |
| |||
1795 | 1791 | | |
1796 | 1792 | | |
1797 | 1793 | | |
1798 | | - | |
1799 | | - | |
1800 | | - | |
1801 | | - | |
1802 | | - | |
1803 | | - | |
1804 | | - | |
1805 | | - | |
1806 | | - | |
1807 | | - | |
| 1794 | + | |
| 1795 | + | |
1808 | 1796 | | |
1809 | 1797 | | |
1810 | 1798 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
648 | 647 | | |
649 | 648 | | |
650 | 649 | | |
| |||
0 commit comments