perf(context): optimize getMapFromFormData performance (#4339)

Co-authored-by: 1911860538 <alxps1911@gmail.com>
This commit is contained in:
Name
2025-09-14 07:29:11 +08:00
committed by GitHub
parent 28172fa682
commit f9bd00a6b7
2 changed files with 99 additions and 5 deletions
+14 -5
View File
@@ -654,14 +654,23 @@ func (c *Context) GetPostFormMap(key string) (map[string]string, bool) {
func getMapFromFormData(m map[string][]string, key string) (map[string]string, bool) {
d := make(map[string]string)
found := false
keyLen := len(key)
for k, v := range m {
if i := strings.IndexByte(k, '['); i >= 1 && k[0:i] == key {
if j := strings.IndexByte(k[i+1:], ']'); j >= 1 {
found = true
d[k[i+1:][:j]] = v[0]
}
if len(k) < keyLen+3 { // key + "[" + at least one char + "]"
continue
}
if k[:keyLen] != key || k[keyLen] != '[' {
continue
}
if j := strings.IndexByte(k[keyLen+1:], ']'); j > 0 {
found = true
d[k[keyLen+1:keyLen+1+j]] = v[0]
}
}
return d, found
}