Substitute AppendBytesStr by append()

This commit is contained in:
Aliaksandr Valialkin
2015-12-19 20:38:10 +02:00
parent ddfa9f5dc0
commit 5ff6be8fee
6 changed files with 35 additions and 33 deletions
+7 -7
View File
@@ -50,7 +50,7 @@ func (a *Args) Len() int {
// Parse parses the given string containing query args.
func (a *Args) Parse(s string) {
a.buf = AppendBytesStr(a.buf[:0], s)
a.buf = append(a.buf[:0], s...)
a.ParseBytes(a.buf)
}
@@ -110,7 +110,7 @@ func (a *Args) WriteTo(w io.Writer) (int64, error) {
// Del deletes argument with the given key from query args.
func (a *Args) Del(key string) {
a.bufKV.key = AppendBytesStr(a.bufKV.key[:0], key)
a.bufKV.key = append(a.bufKV.key[:0], key...)
a.DelBytes(a.bufKV.key)
}
@@ -121,19 +121,19 @@ func (a *Args) DelBytes(key []byte) {
// Set sets 'key=value' argument.
func (a *Args) Set(key, value string) {
a.bufKV.value = AppendBytesStr(a.bufKV.value[:0], value)
a.bufKV.value = append(a.bufKV.value[:0], value...)
a.SetBytesV(key, a.bufKV.value)
}
// SetBytesK sets 'key=value' argument.
func (a *Args) SetBytesK(key []byte, value string) {
a.bufKV.value = AppendBytesStr(a.bufKV.value[:0], value)
a.bufKV.value = append(a.bufKV.value[:0], value...)
a.SetBytesKV(key, a.bufKV.value)
}
// SetBytesV sets 'key=value' argument.
func (a *Args) SetBytesV(key string, value []byte) {
a.bufKV.key = AppendBytesStr(a.bufKV.key[:0], key)
a.bufKV.key = append(a.bufKV.key[:0], key...)
a.SetBytesKV(a.bufKV.key, value)
}
@@ -158,7 +158,7 @@ func (a *Args) PeekBytes(key []byte) []byte {
// Has returns true if the given key exists in Args.
func (a *Args) Has(key string) bool {
a.bufKV.key = AppendBytesStr(a.bufKV.key[:0], key)
a.bufKV.key = append(a.bufKV.key[:0], key...)
return a.HasBytes(a.bufKV.key)
}
@@ -181,7 +181,7 @@ func (a *Args) GetUint(key string) (int, error) {
// SetUint sets uint value for the given key.
func (a *Args) SetUint(key string, value int) {
a.bufKV.key = AppendBytesStr(a.bufKV.key[:0], key)
a.bufKV.key = append(a.bufKV.key[:0], key...)
a.SetUintBytes(a.bufKV.key, value)
}
+2
View File
@@ -332,6 +332,8 @@ func EqualBytesStr(b []byte, s string) bool {
//
// This function has no performance benefits comparing to append(dst, src...).
// It is left here for backwards compatibility only.
//
// This function is deprecated and may be deleted soon.
func AppendBytesStr(dst []byte, src string) []byte {
return append(dst, src...)
}
+5 -5
View File
@@ -51,7 +51,7 @@ func (c *Cookie) Path() []byte {
// SetPath sets cookie path.
func (c *Cookie) SetPath(path string) {
c.buf = AppendBytesStr(c.buf[:0], path)
c.buf = append(c.buf[:0], path...)
c.path = normalizePath(c.path, c.buf)
}
@@ -70,7 +70,7 @@ func (c *Cookie) Domain() []byte {
// SetDomain sets cookie domain.
func (c *Cookie) SetDomain(domain string) {
c.domain = AppendBytesStr(c.domain[:0], domain)
c.domain = append(c.domain[:0], domain...)
}
// SetDomain
@@ -108,7 +108,7 @@ func (c *Cookie) Value() []byte {
// SetValue sets cookie value.
func (c *Cookie) SetValue(value string) {
c.value = AppendBytesStr(c.value[:0], value)
c.value = append(c.value[:0], value...)
}
// SetValueBytes sets cookie value.
@@ -125,7 +125,7 @@ func (c *Cookie) Key() []byte {
// SetKey sets cookie name.
func (c *Cookie) SetKey(key string) {
c.key = AppendBytesStr(c.key[:0], key)
c.key = append(c.key[:0], key...)
}
// SetKeyBytes sets cookie name.
@@ -192,7 +192,7 @@ var errNoCookies = errors.New("no cookies found")
// Parse parses Set-Cookie header.
func (c *Cookie) Parse(src string) error {
c.buf = AppendBytesStr(c.buf[:0], src)
c.buf = append(c.buf[:0], src...)
return c.ParseBytes(c.buf)
}
+13 -13
View File
@@ -193,7 +193,7 @@ func (h *ResponseHeader) ContentType() []byte {
// SetContentType sets Content-Type header value.
func (h *ResponseHeader) SetContentType(contentType string) {
h.contentType = AppendBytesStr(h.contentType[:0], contentType)
h.contentType = append(h.contentType[:0], contentType...)
}
// SetContentTypeBytes sets Content-Type header value.
@@ -208,7 +208,7 @@ func (h *ResponseHeader) Server() []byte {
// SetServer sets Server header value.
func (h *ResponseHeader) SetServer(server string) {
h.server = AppendBytesStr(h.server[:0], server)
h.server = append(h.server[:0], server...)
}
// SetServerBytes sets Server header value.
@@ -225,7 +225,7 @@ func (h *RequestHeader) ContentType() []byte {
// SetContentType sets Content-Type header value.
func (h *RequestHeader) SetContentType(contentType string) {
h.parseRawHeaders()
h.contentType = AppendBytesStr(h.contentType[:0], contentType)
h.contentType = append(h.contentType[:0], contentType...)
}
// SetContentTypeBytes sets Content-Type header value.
@@ -295,7 +295,7 @@ func (h *RequestHeader) Host() []byte {
// SetHost sets Host header value.
func (h *RequestHeader) SetHost(host string) {
h.parseRawHeaders()
h.host = AppendBytesStr(h.host[:0], host)
h.host = append(h.host[:0], host...)
}
// SetHostBytes sets Host header value.
@@ -313,7 +313,7 @@ func (h *RequestHeader) UserAgent() []byte {
// SetUserAgent sets User-Agent header value.
func (h *RequestHeader) SetUserAgent(userAgent string) {
h.parseRawHeaders()
h.userAgent = AppendBytesStr(h.userAgent[:0], userAgent)
h.userAgent = append(h.userAgent[:0], userAgent...)
}
// SetUserAgentBytes sets User-Agent header value.
@@ -347,7 +347,7 @@ func (h *RequestHeader) Method() []byte {
// SetMethod sets HTTP request method.
func (h *RequestHeader) SetMethod(method string) {
h.method = AppendBytesStr(h.method, method)
h.method = append(h.method, method...)
}
// SetMethod sets HTTP request method.
@@ -368,7 +368,7 @@ func (h *RequestHeader) RequestURI() []byte {
// RequestURI must be properly encoded.
// Use URI.RequestURI for constructing proper RequestURI if unsure.
func (h *RequestHeader) SetRequestURI(requestURI string) {
h.requestURI = AppendBytesStr(h.requestURI[:0], requestURI)
h.requestURI = append(h.requestURI[:0], requestURI...)
}
// SetRequestURI sets RequestURI for the first HTTP request line.
@@ -611,7 +611,7 @@ func (h *ResponseHeader) Set(key, value string) {
// SetBytesK sets the given 'key: value' header.
func (h *ResponseHeader) SetBytesK(key []byte, value string) {
h.bufKV.value = AppendBytesStr(h.bufKV.value[:0], value)
h.bufKV.value = append(h.bufKV.value[:0], value...)
h.SetBytesKV(key, h.bufKV.value)
}
@@ -668,13 +668,13 @@ func (h *ResponseHeader) SetCookie(cookie *Cookie) {
// SetCookie sets 'key: value' cookies.
func (h *RequestHeader) SetCookie(key, value string) {
h.bufKV.key = AppendBytesStr(h.bufKV.key[:0], key)
h.bufKV.key = append(h.bufKV.key[:0], key...)
h.SetCookieBytesK(h.bufKV.key, value)
}
// SetCookieBytesK sets 'key: value' cookies.
func (h *RequestHeader) SetCookieBytesK(key []byte, value string) {
h.bufKV.value = AppendBytesStr(h.bufKV.value[:0], value)
h.bufKV.value = append(h.bufKV.value[:0], value...)
h.SetCookieBytesKV(key, h.bufKV.value)
}
@@ -693,7 +693,7 @@ func (h *RequestHeader) Set(key, value string) {
// SetBytesK sets the given 'key: value' header.
func (h *RequestHeader) SetBytesK(key []byte, value string) {
h.bufKV.value = AppendBytesStr(h.bufKV.value[:0], value)
h.bufKV.value = append(h.bufKV.value[:0], value...)
h.SetBytesKV(key, h.bufKV.value)
}
@@ -1494,11 +1494,11 @@ func nextLine(b []byte) ([]byte, []byte, error) {
func initHeaderKV(kv *argsKV, key, value string) {
kv.key = getHeaderKeyBytes(kv, key)
kv.value = AppendBytesStr(kv.value[:0], value)
kv.value = append(kv.value[:0], value...)
}
func getHeaderKeyBytes(kv *argsKV, key string) []byte {
kv.key = AppendBytesStr(kv.key[:0], key)
kv.key = append(kv.key[:0], key...)
normalizeHeaderKey(kv.key)
return kv.key
}
+2 -2
View File
@@ -210,7 +210,7 @@ func (resp *Response) SetBody(body []byte) {
// SetBodyString sets response body.
func (resp *Response) SetBodyString(body string) {
resp.closeBodyStream()
resp.body = AppendBytesStr(resp.body[:0], body)
resp.body = append(resp.body[:0], body...)
}
// ResetBody resets response body.
@@ -236,7 +236,7 @@ func (req *Request) SetBody(body []byte) {
// SetBodyString sets request body.
func (req *Request) SetBodyString(body string) {
req.body = AppendBytesStr(req.body[:0], body)
req.body = append(req.body[:0], body...)
}
// ResetBody resets request body.
+6 -6
View File
@@ -52,7 +52,7 @@ func (x *URI) Hash() []byte {
// SetHash sets URI hash.
func (x *URI) SetHash(hash string) {
x.hash = AppendBytesStr(x.hash[:0], hash)
x.hash = append(x.hash[:0], hash...)
}
// SetHashBytes sets URI hash.
@@ -70,7 +70,7 @@ func (x *URI) QueryString() []byte {
// SetQueryString sets URI query string.
func (x *URI) SetQueryString(queryString string) {
x.queryString = AppendBytesStr(x.queryString[:0], queryString)
x.queryString = append(x.queryString[:0], queryString...)
x.parsedQueryArgs = false
}
@@ -96,7 +96,7 @@ func (x *URI) Path() []byte {
// SetPath sets URI path.
func (x *URI) SetPath(path string) {
x.pathOriginal = AppendBytesStr(x.pathOriginal, path)
x.pathOriginal = append(x.pathOriginal, path...)
x.path = normalizePath(x.path, x.pathOriginal)
}
@@ -128,7 +128,7 @@ func (x *URI) Scheme() []byte {
// SetScheme sets URI scheme, i.e. http, https, ftp, etc.
func (x *URI) SetScheme(scheme string) {
x.scheme = AppendBytesStr(x.scheme[:0], scheme)
x.scheme = append(x.scheme[:0], scheme...)
lowercaseBytes(x.scheme)
}
@@ -173,7 +173,7 @@ func (x *URI) Host() []byte {
// SetHost sets host for the uri.
func (x *URI) SetHost(host string) {
x.host = AppendBytesStr(x.host[:0], host)
x.host = append(x.host[:0], host...)
lowercaseBytes(x.host)
}
@@ -316,7 +316,7 @@ func (x *URI) RequestURI() []byte {
// * Relative path, i.e. xx?yy=abc . In this case the original RequestURI
// is updated according to the new relative path.
func (x *URI) Update(newURI string) {
x.fullURI = AppendBytesStr(x.fullURI[:0], newURI)
x.fullURI = append(x.fullURI[:0], newURI...)
x.UpdateBytes(x.fullURI)
}