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
|
package compression
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -216,13 +217,13 @@ func supportsEncoding(acceptEncoding []byte, ext string) bool {
|
|||||||
if len(acceptEncoding) == 0 {
|
if len(acceptEncoding) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
enc := strings.ToLower(string(acceptEncoding))
|
|
||||||
|
|
||||||
|
// 使用 bytes 操作避免字符串分配
|
||||||
switch ext {
|
switch ext {
|
||||||
case ".br":
|
case ".br":
|
||||||
return strings.Contains(enc, "br")
|
return bytes.Contains(bytes.ToLower(acceptEncoding), []byte("br"))
|
||||||
case ".gz":
|
case ".gz":
|
||||||
return strings.Contains(enc, "gzip")
|
return bytes.Contains(bytes.ToLower(acceptEncoding), []byte("gzip"))
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user