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:
parent
7ad92e95b5
commit
2fdf25dff2
@ -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)]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user