File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,13 @@ func Is(err, reference error) bool {
4343 }
4444 }
4545
46+ if err == nil {
47+ // Err is nil and reference is non-nil, so it cannot match. We
48+ // want to short-circuit the loop below in this case, otherwise
49+ // we're paying the expense of getMark() without need.
50+ return false
51+ }
52+
4653 // Not directly equal. Try harder, using error marks. We don't this
4754 // during the loop above as it may be more expensive.
4855 //
@@ -124,6 +131,14 @@ func IsAny(err error, references ...error) bool {
124131 }
125132 }
126133
134+ if err == nil {
135+ // The mark-based comparison below will never match anything if
136+ // the error is nil, so don't bother with computing the marks in
137+ // that case. This avoids the computational expense of computing
138+ // the reference marks upfront.
139+ return false
140+ }
141+
127142 // Try harder with marks.
128143 // Note: there is a more effective recursive algorithm that ensures
129144 // that any pair of string only gets compared once. Should this
You can’t perform that action at this time.
0 commit comments