small string split join optimization

This commit is contained in:
yusing
2024-12-19 00:54:31 +08:00
parent 654194b274
commit e7be27413c
20 changed files with 160 additions and 50 deletions

View File

@@ -7,6 +7,7 @@ import (
E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/net/types"
"github.com/yusing/go-proxy/internal/utils/strutils"
)
type (
@@ -48,8 +49,9 @@ func (method HTTPMethod) Fulfill(req *http.Request, res *http.Response) bool {
return req.Method == string(method)
}
// Parse implements strutils.Parser.
func (k *HTTPHeader) Parse(v string) error {
split := strings.Split(v, "=")
split := strutils.SplitRune(v, '=')
switch len(split) {
case 1:
split = append(split, "")

View File

@@ -2,9 +2,9 @@ package accesslog
import (
"strconv"
"strings"
E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/utils/strutils"
)
type StatusCodeRange struct {
@@ -18,8 +18,9 @@ func (r *StatusCodeRange) Includes(code int) bool {
return r.Start <= code && code <= r.End
}
// Parse implements strutils.Parser.
func (r *StatusCodeRange) Parse(v string) error {
split := strings.Split(v, "-")
split := strutils.SplitRune(v, '-')
switch len(split) {
case 1:
start, err := strconv.Atoi(split[0])

View File

@@ -6,7 +6,6 @@ import (
"io"
"net"
"net/http"
"strings"
"sync"
"time"
@@ -113,7 +112,7 @@ func fetchUpdateCFIPRange(endpoint string, cfCIDRs *[]*types.CIDR) error {
return err
}
for _, line := range strings.Split(string(body), "\n") {
for _, line := range strutils.SplitLine(string(body)) {
if line == "" {
continue
}

View File

@@ -30,6 +30,7 @@ import (
"github.com/yusing/go-proxy/internal/net/http/accesslog"
"github.com/yusing/go-proxy/internal/net/types"
U "github.com/yusing/go-proxy/internal/utils"
"github.com/yusing/go-proxy/internal/utils/strutils"
"golang.org/x/net/http/httpguts"
)
@@ -528,7 +529,7 @@ func UpgradeType(h http.Header) string {
func RemoveHopByHopHeaders(h http.Header) {
// RFC 7230, section 6.1: Remove headers listed in the "Connection" header.
for _, f := range h["Connection"] {
for _, sf := range strings.Split(f, ",") {
for _, sf := range strutils.SplitComma(f) {
if sf = textproto.TrimString(sf); sf != "" {
h.Del(sf)
}