File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -31,16 +31,19 @@ fn compute(input: &u32, output: &mut u32) {
31
31
if * input > 5 {
32
32
* output *= 2 ;
33
33
}
34
+ // remember that `output` will be `2` if `input > 10`
34
35
}
35
36
```
36
37
37
38
We would * like* to be able to optimize it to the following function:
38
39
39
40
``` rust
40
41
fn compute (input : & u32 , output : & mut u32 ) {
41
- let cached_input = * input ; // keep *input in a register
42
+ let cached_input = * input ; // keep ` *input` in a register
42
43
if cached_input > 10 {
43
- * output = 2 ; // x > 10 implies x > 5, so double and exit immediately
44
+ // x > 10 implies x > 5, so remove the first if condition,
45
+ // set it to `2`, and exit immediately
46
+ * output = 2 ;
44
47
} else if cached_input > 5 {
45
48
* output *= 2 ;
46
49
}
You can’t perform that action at this time.
0 commit comments