Skip to content

Commit 46f2b8b

Browse files
authored
refactor: replace Split in loops with more efficient SplitSeq (#2969)
* refactor: replace Split in loops with more efficient SplitSeq Signed-off-by: box4wangjing <box4wangjing@outlook.com> * refactor: replace Split in loops with more efficient SplitSeq Signed-off-by: box4wangjing <box4wangjing@outlook.com> --------- Signed-off-by: box4wangjing <box4wangjing@outlook.com>
1 parent 7d1fed0 commit 46f2b8b

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

middleware/extractor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func createExtractors(lookups string, limit uint) ([]ValuesExtractor, error) {
8585
limit = extractorLimit
8686
}
8787

88-
sources := strings.Split(lookups, ",")
88+
sources := strings.SplitSeq(lookups, ",")
8989
var extractors = make([]ValuesExtractor, 0)
90-
for _, source := range sources {
90+
for source := range sources {
9191
parts := strings.Split(source, ":")
9292
if len(parts) < 2 {
9393
return nil, fmt.Errorf("extractor source for lookup could not be split into needed parts: %v", source)

router_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,8 +2235,8 @@ func testRouterAPI(t *testing.T, api []testRoute) {
22352235
c.SetRequest(httptest.NewRequest(route.Method, route.Path, nil))
22362236
e.router.Route(c)
22372237

2238-
tokens := strings.Split(route.Path[1:], "/")
2239-
for _, token := range tokens {
2238+
tokens := strings.SplitSeq(route.Path[1:], "/")
2239+
for token := range tokens {
22402240
if token[0] == ':' {
22412241
assert.Equal(t, c.pathValues.GetOr(token[1:], "---none---"), token)
22422242
}

0 commit comments

Comments
 (0)