diff options
author | Shulhan <ms@kilabit.info> | 2019-02-02 18:13:33 +0700 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2019-02-02 11:13:33 +0000 |
commit | 9574c37fb8573364003841d9b523ee7df95aedc8 (patch) | |
tree | 10652140e87660fffe669ed0fedc5a843aba3cc7 /args.go | |
parent | all: fix typo on comments (diff) | |
download | fasthttp-9574c37fb8573364003841d9b523ee7df95aedc8.tar.gz fasthttp-9574c37fb8573364003841d9b523ee7df95aedc8.tar.bz2 fasthttp-9574c37fb8573364003841d9b523ee7df95aedc8.zip |
Various changes regarding code readibility (#523)
* all: use sort.Strings when applicable
Basically, sort.Strings is the shortcut of Sort(StringSlice(a)) but its
more readable.
* all: replace string(bytes.Buffer.Bytes()) with bytes.Buffer.String()
Although its only occured on test files, it may be worth to simplified it.
* http_test: simplify strings.Index with strings.Contains
Both have the same O(n), but strings.Contains more readable on
if-condition.
* args: simplify if-condition check on boolean value
* all: simplify variable initialization
If we assign the variable after declaring it, we can simplify it using
":=" operator or "= value".
The reader can still known the type of variable from the struct name or
variable type before assignment operator.
Diffstat (limited to 'args.go')
-rw-r--r-- | args.go | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -134,7 +134,7 @@ func (a *Args) AppendBytes(dst []byte) []byte { for i, n := 0, len(a.args); i < n; i++ { kv := &a.args[i] dst = AppendQuotedArg(dst, kv.key) - if kv.noValue == argsHasValue { + if !kv.noValue { dst = append(dst, '=') if len(kv.value) > 0 { dst = AppendQuotedArg(dst, kv.value) @@ -370,7 +370,7 @@ func copyArgs(dst, src []argsKV) []argsKV { dstKV := &dst[i] srcKV := &src[i] dstKV.key = append(dstKV.key[:0], srcKV.key...) - if srcKV.noValue == argsNoValue { + if srcKV.noValue { dstKV.value = dstKV.value[:0] } else { dstKV.value = append(dstKV.value[:0], srcKV.value...) @@ -407,7 +407,7 @@ func setArg(h []argsKV, key, value string, noValue bool) []argsKV { for i := 0; i < n; i++ { kv := &h[i] if key == string(kv.key) { - if noValue == argsNoValue { + if noValue { kv.value = kv.value[:0] } else { kv.value = append(kv.value[:0], value...) @@ -427,7 +427,7 @@ func appendArg(args []argsKV, key, value string, noValue bool) []argsKV { var kv *argsKV args, kv = allocArg(args) kv.key = append(kv.key[:0], key...) - if noValue == argsNoValue { + if noValue { kv.value = kv.value[:0] } else { kv.value = append(kv.value[:0], value...) |