mirror of
https://github.com/aykhans/sarin.git
synced 2026-08-28 02:54:32 +00:00
perf: replace status code string map with an indexed table
This commit is contained in:
@@ -12,19 +12,19 @@ import (
|
||||
const dryRunResponseKey = "dry-run"
|
||||
|
||||
// statusCodeStrings contains pre-computed string representations for HTTP status codes 100-599.
|
||||
var statusCodeStrings = func() map[int]string {
|
||||
m := make(map[int]string, 500)
|
||||
for i := 100; i < 600; i++ {
|
||||
m[i] = strconv.Itoa(i)
|
||||
var statusCodeStrings = func() [500]string {
|
||||
var codes [500]string
|
||||
for i := range codes {
|
||||
codes[i] = strconv.Itoa(i + 100)
|
||||
}
|
||||
return m
|
||||
return codes
|
||||
}()
|
||||
|
||||
// statusCodeToString returns a string representation of the HTTP status code.
|
||||
// Uses a pre-computed map for codes 100-599, falls back to strconv.Itoa for others.
|
||||
// Uses a pre-computed table for codes 100-599, falls back to strconv.Itoa for others.
|
||||
func statusCodeToString(code int) string {
|
||||
if s, ok := statusCodeStrings[code]; ok {
|
||||
return s
|
||||
if i := code - 100; i >= 0 && i < len(statusCodeStrings) {
|
||||
return statusCodeStrings[i]
|
||||
}
|
||||
return strconv.Itoa(code)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user