Skip to content

Commit

Permalink
Don't parse params.
Browse files Browse the repository at this point in the history
According to https://httpwg.org/specs/rfc9110.html#field.accept,
parsing parameters has been removed from the spec as it's no longer
widely used.

Removing parameter parsing means that Accept will only ever allocate
once.

Compared to the previous commit:

goos: darwin
goarch: arm64
pkg: github.com/munnerz/goautoneg
                                                                                                          │ step-2-slices-sort.txt │     step-4-without-params.txt      │
                                                                                                          │         sec/op         │   sec/op     vs base               │
ParseAccept/#00-10                                                                                                     6.524n ± 0%   6.540n ± 1%        ~ (p=0.056 n=6)
ParseAccept/application/json-10                                                                                        65.66n ± 0%   66.41n ± 1%   +1.15% (p=0.009 n=6)
ParseAccept/application/json,text/plain-10                                                                             125.3n ± 0%   123.7n ± 1%   -1.28% (p=0.026 n=6)
ParseAccept/application/json;q=0.9,text/plain-10                                                                       188.1n ± 0%   164.5n ± 1%  -12.54% (p=0.002 n=6)
ParseAccept/application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5-10              615.6n ± 1%   528.9n ± 0%  -14.08% (p=0.002 n=6)
geomean                                                                                                                90.93n        85.90n        -5.54%

                                                                                                          │ step-2-slices-sort.txt │      step-4-without-params.txt      │
                                                                                                          │          B/op          │    B/op     vs base                 │
ParseAccept/#00-10                                                                                                    0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=6) ¹
ParseAccept/application/json-10                                                                                       48.00 ± 0%     48.00 ± 0%        ~ (p=1.000 n=6) ¹
ParseAccept/application/json,text/plain-10                                                                            96.00 ± 0%     80.00 ± 0%  -16.67% (p=0.002 n=6)
ParseAccept/application/json;q=0.9,text/plain-10                                                                     144.00 ± 0%     80.00 ± 0%  -44.44% (p=0.002 n=6)
ParseAccept/application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5-10             432.0 ± 0%     240.0 ± 0%  -44.44% (p=0.002 n=6)
geomean                                                                                                                          ²               -23.78%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                                                                                          │ step-2-slices-sort.txt │      step-4-without-params.txt      │
                                                                                                          │       allocs/op        │ allocs/op   vs base                 │
ParseAccept/#00-10                                                                                                    0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=6) ¹
ParseAccept/application/json-10                                                                                       1.000 ± 0%     1.000 ± 0%        ~ (p=1.000 n=6) ¹
ParseAccept/application/json,text/plain-10                                                                            1.000 ± 0%     1.000 ± 0%        ~ (p=1.000 n=6) ¹
ParseAccept/application/json;q=0.9,text/plain-10                                                                      2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.002 n=6)
ParseAccept/application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5-10             4.000 ± 0%     1.000 ± 0%  -75.00% (p=0.002 n=6)
geomean                                                                                                                          ²               -34.02%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean
  • Loading branch information
charleskorn committed Mar 3, 2023
1 parent 9895b45 commit 7248a2f
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions autoneg.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
type Accept struct {
Type, SubType string
Q float64
Params map[string]string
}

// acceptSlice is defined to implement sort interface.
Expand Down Expand Up @@ -114,7 +113,6 @@ func ParseAccept(header string) acceptSlice {
continue
}

a.Params = make(map[string]string)
for len(remainingPart) > 0 {
sp, remainingPart = nextSplitElement(remainingPart, ";")
sp0, spRemaining = nextSplitElement(sp, "=")
Expand All @@ -129,8 +127,6 @@ func ParseAccept(header string) acceptSlice {
token := strings.TrimFunc(sp0, stringTrimSpaceCutset)
if token == "q" {
a.Q, _ = strconv.ParseFloat(sp1, 32)
} else {
a.Params[token] = strings.TrimFunc(sp1, stringTrimSpaceCutset)
}
}

Expand Down

0 comments on commit 7248a2f

Please sign in to comment.