File tree 1 file changed +9
-13
lines changed
1 file changed +9
-13
lines changed Original file line number Diff line number Diff line change @@ -30,27 +30,23 @@ type TNodePool = TNonFreePooledMemManager<TNode, 64>;
30
30
impl TNode {
31
31
#[ inline( always) ]
32
32
fn check_node ( node : * mut TNode ) -> i32 {
33
- unsafe {
34
- // `node` is never itself null when passed into this function. Also, anecdotally, IMO Rust's
35
- // syntax for dereferencing raw pointers could not possibly be worse than what it is.
36
- if !( ( * node) . right . is_null ( ) && ( * node) . left . is_null ( ) ) {
37
- return 1 + TNode :: check_node ( ( * node) . right ) + TNode :: check_node ( ( * node) . left ) ;
38
- }
33
+ // `node` is never itself null when passed into this function.
34
+ let node_ref = unsafe { & mut * node } ;
35
+ if !( node_ref. right . is_null ( ) && node_ref. left . is_null ( ) ) {
36
+ return 1 + TNode :: check_node ( node_ref. right ) + TNode :: check_node ( node_ref. left ) ;
39
37
}
40
38
1
41
39
}
42
40
43
41
// This can't be `&mut` instead of `*mut` due to the lifetime / borrowing rules.
44
42
#[ inline( always) ]
45
43
fn make_tree ( depth : i32 , node_pool : * mut TNodePool ) -> * mut TNode {
46
- unsafe {
47
- let result = ( * node_pool) . new_item ( ) ;
48
- if depth > 0 {
49
- ( * result) . right = TNode :: make_tree ( depth - 1 , node_pool) ;
50
- ( * result) . left = TNode :: make_tree ( depth - 1 , node_pool) ;
51
- }
52
- result
44
+ let res_ref = unsafe { & mut * ( ( * node_pool) . new_item ( ) ) } ;
45
+ if depth > 0 {
46
+ res_ref. right = TNode :: make_tree ( depth - 1 , node_pool) ;
47
+ res_ref. left = TNode :: make_tree ( depth - 1 , node_pool) ;
53
48
}
49
+ res_ref as * mut T
54
50
}
55
51
}
56
52
You can’t perform that action at this time.
0 commit comments