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

gomock: fix matcher's degenerate quadratic path. #103

Merged
merged 1 commit into from
Aug 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions gomock/callset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package gomock

import (
"bytes"
"errors"
"fmt"
)
Expand Down Expand Up @@ -65,22 +66,22 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac

// Search through the unordered set of calls expected on a method on a
// receiver.
callsErrors := ""
var callsErrors bytes.Buffer
for _, call := range calls {
// A call should not normally still be here if exhausted,
// but it can happen if, for instance, .Times(0) was used.
// Pretend the call doesn't match.
if call.exhausted() {
callsErrors += "\nThe call was exhausted."
callsErrors.WriteString("\nThe call was exhausted.")
continue
}
err := call.matches(args)
if err != nil {
callsErrors += "\n" + err.Error()
fmt.Fprintf(&callsErrors, "\n%v", err)
} else {
return call, nil
}
}

return nil, fmt.Errorf(callsErrors)
return nil, fmt.Errorf(callsErrors.String())
}