Skip to content

Commit d81d37a

Browse files
authored
performance,typo: prealloc slice for performance and fix typo (#816)
* prealloc for performance * mispell
1 parent 5882460 commit d81d37a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

consumergroup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ type Generation struct {
326326
// between Start and close. lock protects all of them. done is closed
327327
// when the generation is ending in order to signal that the generation
328328
// should start self-desructing. closed protects against double-closing
329-
// the done chan. routines is a count of runing go routines that have been
329+
// the done chan. routines is a count of running go routines that have been
330330
// launched by Start. joined will be closed by the last go routine to exit.
331331
lock sync.Mutex
332332
done chan struct{}

createtopics.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ func (t *TopicConfig) configs() []createtopics.RequestConfig {
209209
}
210210

211211
func (t TopicConfig) toCreateTopicsRequestV0Topic() createTopicsRequestV0Topic {
212-
var requestV0ReplicaAssignments []createTopicsRequestV0ReplicaAssignment
212+
requestV0ReplicaAssignments := make([]createTopicsRequestV0ReplicaAssignment, 0, len(t.ReplicaAssignments))
213213
for _, a := range t.ReplicaAssignments {
214214
requestV0ReplicaAssignments = append(
215215
requestV0ReplicaAssignments,
216216
a.toCreateTopicsRequestV0ReplicaAssignment())
217217
}
218-
var requestV0ConfigEntries []createTopicsRequestV0ConfigEntry
218+
requestV0ConfigEntries := make([]createTopicsRequestV0ConfigEntry, 0, len(t.ConfigEntries))
219219
for _, c := range t.ConfigEntries {
220220
requestV0ConfigEntries = append(
221221
requestV0ConfigEntries,
@@ -377,7 +377,7 @@ func (c *Conn) createTopics(request createTopicsRequestV0) (createTopicsResponse
377377
// operational semantics. In other words, if CreateTopics is invoked with a
378378
// configuration for an existing topic, it will have no effect.
379379
func (c *Conn) CreateTopics(topics ...TopicConfig) error {
380-
var requestV0Topics []createTopicsRequestV0Topic
380+
requestV0Topics := make([]createTopicsRequestV0Topic, 0, len(topics))
381381
for _, t := range topics {
382382
requestV0Topics = append(
383383
requestV0Topics,

reader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ func TestConsumerGroupWithGroupTopicsMultple(t *testing.T) {
15521552

15531553
time.Sleep(time.Second)
15541554

1555-
var msgs []Message
1555+
msgs := make([]Message, 0, len(conf.GroupTopics))
15561556
for _, topic := range conf.GroupTopics {
15571557
msgs = append(msgs, Message{Topic: topic})
15581558
}

0 commit comments

Comments
 (0)