perf(compression): use bytes operations to avoid string allocation
- Replace strings.ToLower(string(...)) with bytes.ToLower - Reduces memory allocation in hot path for Accept-Encoding checks Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
73ef3a938b
commit
5593a729b8
@ -25,6 +25,7 @@
|
||||
package compression
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -216,13 +217,13 @@ func supportsEncoding(acceptEncoding []byte, ext string) bool {
|
||||
if len(acceptEncoding) == 0 {
|
||||
return false
|
||||
}
|
||||
enc := strings.ToLower(string(acceptEncoding))
|
||||
|
||||
// 使用 bytes 操作避免字符串分配
|
||||
switch ext {
|
||||
case ".br":
|
||||
return strings.Contains(enc, "br")
|
||||
return bytes.Contains(bytes.ToLower(acceptEncoding), []byte("br"))
|
||||
case ".gz":
|
||||
return strings.Contains(enc, "gzip")
|
||||
return bytes.Contains(bytes.ToLower(acceptEncoding), []byte("gzip"))
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user