1
0
mirror of https://github.com/golang/go synced 2024-11-22 22:30:02 -07:00

os:ReadFile: don't check for re-allocation in the first iteration

This commit is contained in:
Jabar Asadi 2023-05-27 21:47:40 +02:00
parent 7ad92e95b5
commit 2fdf25dff2
No known key found for this signature in database
GPG Key ID: B865AD8DBA1BB44E

View File

@ -737,10 +737,6 @@ func ReadFile(name string) ([]byte, error) {
data := make([]byte, 0, size)
for {
if len(data) >= cap(data) {
d := append(data[:cap(data)], 0)
data = d[:len(data)]
}
n, err := f.Read(data[len(data):cap(data)])
data = data[:len(data)+n]
if err != nil {
@ -749,6 +745,11 @@ func ReadFile(name string) ([]byte, error) {
}
return data, err
}
if len(data) >= cap(data) {
d := append(data[:cap(data)], 0)
data = d[:len(data)]
}
}
}