Commit f9662e8
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 85196be commit f9662e8
File tree
6 files changed
+29
-27
lines changed- src/enc
6 files changed
+29
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | | - | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
| 447 | + | |
452 | 448 | | |
453 | 449 | | |
454 | 450 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
177 | 176 | | |
178 | 177 | | |
179 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1728 | 1728 | | |
1729 | 1729 | | |
1730 | 1730 | | |
1731 | | - | |
1732 | | - | |
1733 | | - | |
1734 | | - | |
1735 | | - | |
1736 | | - | |
1737 | | - | |
1738 | | - | |
1739 | | - | |
1740 | | - | |
| 1731 | + | |
| 1732 | + | |
1741 | 1733 | | |
1742 | 1734 | | |
1743 | 1735 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
635 | 634 | | |
636 | 635 | | |
637 | 636 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
0 commit comments