remove ForEach pattern, allocates in TinyGo

This commit is contained in:
Patricio Whittingslow
2026-07-25 22:52:15 -03:00
parent d5a5e44ddf
commit 2ac4380442
5 changed files with 70 additions and 207 deletions
+9 -6
View File
@@ -4,6 +4,8 @@ import (
"context"
"errors"
"strings"
"github.com/soypat/lneto/http/httpraw"
"testing"
"time"
@@ -461,10 +463,11 @@ func TestHandleMuxOnPath(t *testing.T) {
var gotPath, gotQuery string
sm.Handle("GET /search", func(ex *Exchange) {
gotPath = string(ex.RequestPath())
ex.ForEachQueryRaw(func(rawkey, rawval []byte) bool {
rawkey, rawval, rest := httpraw.NextQueryPair(ex.RequestQuery())
for rawkey != nil {
gotQuery += string(rawkey) + "=" + string(rawval) + ";"
return true
})
rawkey, rawval, rest = httpraw.NextQueryPair(rest)
}
ex.WriteHeader(200)
})
conn := serve(t, "GET /search?q=go&n=1 HTTP/1.1\r\nHost: h\r\n\r\n", &sm)
@@ -490,9 +493,9 @@ func TestExchangeAppendQuery(t *testing.T) {
}{
{uri: "/x?q=go", key: "q", want: "go", wantPresent: true},
{uri: "/x?q=go&n=1", key: "n", want: "1", wantPresent: true},
{uri: "/x?a=1&a=2", key: "a", want: "1", wantPresent: true}, // First match wins.
{uri: "/x?q=go", key: "nope", want: "", wantPresent: false}, // Absent.
{uri: "/x", key: "q", want: "", wantPresent: false}, // No query at all.
{uri: "/x?a=1&a=2", key: "a", want: "1", wantPresent: true}, // First match wins.
{uri: "/x?q=go", key: "nope", want: "", wantPresent: false}, // Absent.
{uri: "/x", key: "q", want: "", wantPresent: false}, // No query at all.
{uri: "/x?debug&q=go", key: "debug", want: "", wantPresent: true}, // Flag: present, no value.
{uri: "/x?q=", key: "q", want: "", wantPresent: true}, // Present, empty.
// Decoding is opt-in and applies to the value only.