Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 18f6dd1

Browse files
authored
Merge pull request #103 from matttproud/fix/quadratic-reporting-cost
gomock: fix matcher's degenerate quadratic path.
2 parents 0553d24 + d17f086 commit 18f6dd1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

gomock/callset.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package gomock
1616

1717
import (
18+
"bytes"
1819
"errors"
1920
"fmt"
2021
)
@@ -65,22 +66,22 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac
6566

6667
// Search through the unordered set of calls expected on a method on a
6768
// receiver.
68-
callsErrors := ""
69+
var callsErrors bytes.Buffer
6970
for _, call := range calls {
7071
// A call should not normally still be here if exhausted,
7172
// but it can happen if, for instance, .Times(0) was used.
7273
// Pretend the call doesn't match.
7374
if call.exhausted() {
74-
callsErrors += "\nThe call was exhausted."
75+
callsErrors.WriteString("\nThe call was exhausted.")
7576
continue
7677
}
7778
err := call.matches(args)
7879
if err != nil {
79-
callsErrors += "\n" + err.Error()
80+
fmt.Fprintf(&callsErrors, "\n%v", err)
8081
} else {
8182
return call, nil
8283
}
8384
}
8485

85-
return nil, fmt.Errorf(callsErrors)
86+
return nil, fmt.Errorf(callsErrors.String())
8687
}

0 commit comments

Comments
 (0)