refactor RequestParseForm and achieve greatness in API design

This commit is contained in:
Patricio Whittingslow
2026-07-30 00:59:11 -03:00
parent 1985688076
commit 7503e88cb1
8 changed files with 245 additions and 91 deletions
+5 -2
View File
@@ -112,10 +112,13 @@ func BenchmarkRequestParseForm(b *testing.B) {
const request = "POST /f HTTP/1.1\r\nHost: tinygo.org\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\nContent-Length: 27\r\n\r\n" +
"user=gopher&msg=hello+world"
buf := make([]byte, 64)
// The form owns its memory now, so pre-size it and forbid growth: an
// allocation on this path is the failure the benchmark is watching for.
benchForm.Reset(make([]byte, 0, 64), 2)
benchForm.EnableBufferGrowth(false)
var mux MuxSlice
mux.Handle("POST /f", func(ex *Exchange) {
err := ex.RequestParseForm(&benchForm, buf)
err := ex.RequestParseForm(&benchForm, false, false)
if err != nil || benchForm.Len() != 2 {
panic("invalid result")
}