Skip to content

Commit

Permalink
fix: fix slice init length (#7731)
Browse files Browse the repository at this point in the history
Initialize a slice with a capacity of len(nameToString) rather than initializing
the length of this slice.

Signed-off-by: huochexizhan <[email protected]>
  • Loading branch information
huochexizhan authored Oct 8, 2024
1 parent 0a543d1 commit a6dc97c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ratelimits/limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestLoadAndParseOverrideLimits(t *testing.T) {
// Burst cannot be 0.
_, err = loadAndParseOverrideLimits("testdata/busted_override_burst_0.yml")
test.AssertError(t, err, "single override limit with burst=0")
test.Assert(t, !os.IsNotExist(err), "test file should exist")
test.AssertContains(t, err.Error(), "invalid burst")

// Id cannot be empty.
_, err = loadAndParseOverrideLimits("testdata/busted_override_empty_id.yml")
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestLoadAndParseDefaultLimits(t *testing.T) {
// Burst cannot be 0.
_, err = loadAndParseDefaultLimits("testdata/busted_default_burst_0.yml")
test.AssertError(t, err, "single default limit with burst=0")
test.Assert(t, !os.IsNotExist(err), "test file should exist")
test.AssertContains(t, err.Error(), "invalid burst")

// Name cannot be empty.
_, err = loadAndParseDefaultLimits("testdata/busted_default_empty_name.yml")
Expand Down
2 changes: 1 addition & 1 deletion ratelimits/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ var stringToName = func() map[string]Name {

// limitNames is a slice of all rate limit names.
var limitNames = func() []string {
names := make([]string, len(nameToString))
names := make([]string, 0, len(nameToString))
for _, v := range nameToString {
names = append(names, v)
}
Expand Down

0 comments on commit a6dc97c

Please sign in to comment.