Fix unnecessary allocations due to Index calls

This commit is contained in:
shubhendra 2021-02-25 15:58:42 +05:30
parent fea886b223
commit b849cfc18c
No known key found for this signature in database
GPG Key ID: 9AFEF5C98D542137
3 changed files with 20 additions and 6 deletions

12
.deepsource.toml Normal file
View File

@ -0,0 +1,12 @@
version = 1
test_patterns = ["**/*_test.go"]
exclude_patterns = ["scripts/**"]
[[analyzers]]
name = "go"
enabled = true
[analyzers.meta]
import_paths = ["github.com/beego/beego"]

View File

@ -15,6 +15,7 @@
package httplib
import (
"bytes"
"errors"
"io/ioutil"
"net"
@ -66,7 +67,7 @@ func TestDoRequest(t *testing.T) {
}
func TestGet(t *testing.T) {
req := Get(getUrl)
b, err := req.Bytes()
if err != nil {
@ -222,7 +223,7 @@ func TestWithSetting(t *testing.T) {
}
func TestToJson(t *testing.T) {
req := Get(ipUrl)
resp, err := req.Response()
if err != nil {
@ -261,7 +262,7 @@ func TestToFile(t *testing.T) {
}
defer os.Remove(f)
b, err := ioutil.ReadFile(f)
if n := strings.Index(string(b), "origin"); n == -1 {
if n := bytes.Index(b, []byte("origin")); n == -1 {
t.Fatal(err)
}
}
@ -275,7 +276,7 @@ func TestToFileDir(t *testing.T) {
}
defer os.RemoveAll("./files")
b, err := ioutil.ReadFile(f)
if n := strings.Index(string(b), "origin"); n == -1 {
if n := bytes.Index(b, []byte("origin")); n == -1 {
t.Fatal(err)
}
}

View File

@ -15,6 +15,7 @@
package httplib
import (
"bytes"
"context"
"errors"
"io/ioutil"
@ -259,7 +260,7 @@ func TestToFile(t *testing.T) {
}
defer os.Remove(f)
b, err := ioutil.ReadFile(f)
if n := strings.Index(string(b), "origin"); n == -1 {
if n := bytes.Index(b, []byte("origin")); n == -1 {
t.Fatal(err)
}
}
@ -273,7 +274,7 @@ func TestToFileDir(t *testing.T) {
}
defer os.RemoveAll("./files")
b, err := ioutil.ReadFile(f)
if n := strings.Index(string(b), "origin"); n == -1 {
if n := bytes.Index(b, []byte("origin")); n == -1 {
t.Fatal(err)
}
}