Skip to content
Myr

use IndexByte replace Split to improve performance (#2500)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by xyb · committed by GitHub · parent 540b1ef · Browse files · 2 files+10 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: yonbiaoxiao <yonbiaoxiao@tencent.com>
  • Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>

Diff stats

2 files+10 added−1 removed

  • other:+10 added−1 removed

2 files+10 added−1 removed

modified:utils_test.go+6 added
16 unmodified lines
17func init() {18 SetMode(TestMode)19}2021func BenchmarkParseAccept(b *testing.B) {22 for i := 0; i < b.N; i++ {23 parseAccept("text/html , application/xhtml+xml,application/xml;q=0.9, */* ;q=0.8")24 }25}2627type testStruct struct {28 T *testing.T29}30
115 unmodified lines
modified:utils.go+4 added-1 removed
101 unmodified lines
102func parseAccept(acceptHeader string) []string {103 parts := strings.Split(acceptHeader, ",")104 out := make([]string, 0, len(parts))105 for _, part := range parts {106 if i := strings.IndexByte(part, ';'); i > 0 {107 part = part[:i]108 }106 if part = strings.TrimSpace(strings.Split(part, ";")[0]); part != "" {109 if part = strings.TrimSpace(part); part != "" {110 out = append(out, part)111 }112 }113 return out
40 unmodified lines