Speed up the fast path for assert_eq! and assert_ne! · rust-lang/rust@5a7cd84 (original) (raw)
`@@ -45,9 +45,12 @@ macro_rules! assert_eq {
`
45
45
`match (&$left, &$right) {
`
46
46
`(left_val, right_val) => {
`
47
47
`if !(*left_val == *right_val) {
`
``
48
`+
// The reborrows below are intentional. Without them, the stack slot for the
`
``
49
`+
// borrow is initialized even before the values are compared, leading to a
`
``
50
`+
// noticeable slow down.
`
48
51
`` panic!(r#"assertion failed: (left == right)
``
49
52
`` left: {:?}
,
``
50
``
`` -
right: {:?}
"#, left_val, right_val)
``
``
53
`` +
right: {:?}
"#, &*left_val, &*right_val)
``
51
54
`}
`
52
55
`}
`
53
56
`}
`
`@@ -59,9 +62,12 @@ macro_rules! assert_eq {
`
59
62
`match (&($left), &($right)) {
`
60
63
`(left_val, right_val) => {
`
61
64
`if !(*left_val == *right_val) {
`
``
65
`+
// The reborrows below are intentional. Without them, the stack slot for the
`
``
66
`+
// borrow is initialized even before the values are compared, leading to a
`
``
67
`+
// noticeable slow down.
`
62
68
`` panic!(r#"assertion failed: (left == right)
``
63
69
`` left: {:?}
,
``
64
``
`` -
right: {:?}
: {}"#, left_val, right_val,
``
``
70
`` +
right: {:?}
: {}"#, &*left_val, &*right_val,
``
65
71
` format_args!($($arg)+))
`
66
72
`}
`
67
73
`}
`
`@@ -96,9 +102,12 @@ macro_rules! assert_ne {
`
96
102
`match (&$left, &$right) {
`
97
103
`(left_val, right_val) => {
`
98
104
`if *left_val == *right_val {
`
``
105
`+
// The reborrows below are intentional. Without them, the stack slot for the
`
``
106
`+
// borrow is initialized even before the values are compared, leading to a
`
``
107
`+
// noticeable slow down.
`
99
108
`` panic!(r#"assertion failed: (left != right)
``
100
109
`` left: {:?}
,
``
101
``
`` -
right: {:?}
"#, left_val, right_val)
``
``
110
`` +
right: {:?}
"#, &*left_val, &*right_val)
``
102
111
`}
`
103
112
`}
`
104
113
`}
`
`@@ -110,9 +119,12 @@ macro_rules! assert_ne {
`
110
119
`match (&($left), &($right)) {
`
111
120
`(left_val, right_val) => {
`
112
121
`if *left_val == *right_val {
`
``
122
`+
// The reborrows below are intentional. Without them, the stack slot for the
`
``
123
`+
// borrow is initialized even before the values are compared, leading to a
`
``
124
`+
// noticeable slow down.
`
113
125
`` panic!(r#"assertion failed: (left != right)
``
114
126
`` left: {:?}
,
``
115
``
`` -
right: {:?}
: {}"#, left_val, right_val,
``
``
127
`` +
right: {:?}
: {}"#, &*left_val, &*right_val,
``
116
128
` format_args!($($arg)+))
`
117
129
`}
`
118
130
`}
`