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
3 changed files with 20 additions and 6 deletions

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)
}
}