8000 ♻️ refactor: Return fast from parseToStruct() when data is empty by billyplus · Pull Request #3402 · gofiber/fiber · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

♻️ refactor: Return fast from parseToStruct() when data is empty #3402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,10 +1082,16 @@

// ParamsParser binds the param string to a struct.
func (c *Ctx) ParamsParser(out interface{}) error {
params := make(map[string][]string, len(c.route.Params))
// fast return
l := len(c.route.Params)
if l == 0 {
return nil
}
params := make(map[string][]string, l)
for _, param := range c.route.Params {
params[param] = append(params[param], c.Params(param))
}

return c.parseToStruct(paramsTag, out, params)
}

Expand Down Expand Up @@ -1308,6 +1314,10 @@
}

func (*Ctx) parseToStruct(aliasTag string, out interface{}, data map[string][]string) error {
// fast return
if len(data) == 0 {
return nil
}
// Get decoder from pool
schemaDecoder, ok := decoderPoolMap[aliasTag].Get().(*schema.Decoder)
if !ok {
Expand Down Expand Up @@ -1838,14 +1848,14 @@
buf := bytebufferpool.Get()

// Start with the ID, converting it to a hex string without fmt.Sprintf
buf.WriteByte('#') //nolint:errcheck // Not needed here

Check failure on line 1851 in ctx.go

View workflow job for this annotation

GitHub Actions / lint

G104: Errors unhandled. (gosec)
// Convert ID to hexadecimal
id := strconv.FormatUint(c.fasthttp.ID(), 16)
// Pad with leading zeros to ensure 16 characters
for i := 0; i < (16 - len(id)); i++ {
buf.WriteByte('0') //nolint:errcheck // Not needed here

Check failure on line 1856 in ctx.go

View workflow job for this annotation

GitHub Actions / lint

G104: Errors unhandled. (gosec)
}
buf.WriteString(id) //nolint:errcheck // Not needed here

Check failure on line 1858 in ctx.go

View workflow job for this annotation

GitHub Actions / lint

G104: Errors unhandled. (gosec)
buf.WriteString(" - ") //nolint:errcheck // Not needed here

// Add local and remote addresses directly
Expand Down
Loading
0