Gerrit Bot has uploaded this change for review.
io: ReadFile: don't check for slice re-allocation in the first iteration
At the beginning of the for-loop iteration size > 0 always. so in
the first iteration, this check is not necessary. we can move this check to
after the read operation.
besides this change >= operator also can be simplified to == in the if-statement
Change-Id: I205e4a842ced74f31124b45a39b70523b56ad840
GitHub-Last-Rev: b53bfd551cf7e57f12285e50bab083d349144a63
GitHub-Pull-Request: golang/go#60473
---
M src/os/file.go
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/os/file.go b/src/os/file.go
index 7fd2f5d..4b9f1df 100644
--- a/src/os/file.go
+++ b/src/os/file.go
@@ -737,10 +737,6 @@
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 @@
}
return data, err
}
+
+ if len(data) == cap(data) {
+ d := append(data[:cap(data)], 0)
+ data = d[:len(data)]
+ }
}
}
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Russ Cox.
1 comment:
File src/os/file.go:
Patch Set #1, Line 749: if len(data) == cap(data) {
yes, == is correct here, but i prefer the defensive programming of >=. after too many years programming with corrupted data and other bugs. i'd rather you left it as is, because the existing code is not wrong. there is no need to change it.
i may be the only person who feels this way, though.
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Rob Pike, Russ Cox.
1 comment:
File src/os/file.go:
Patch Set #1, Line 749: if len(data) == cap(data) {
yes, == is correct here, but i prefer the defensive programming of >=. […]
sure, Done.
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Rob Pike, Russ Cox.
Gerrit Bot uploaded patch set #2 to this change.
io: ReadFile: don't check for slice re-allocation in the first iteration
At the beginning of the for-loop iteration size > 0 always. so in
the first iteration, this check is not necessary. we can move this check to
after the read operation.
besides this change >= operator also can be simplified to == in the if-statement
Change-Id: I205e4a842ced74f31124b45a39b70523b56ad840
GitHub-Last-Rev: 1c568d229551eca3a7b6fbb51b76ec6cc7e8e899
GitHub-Pull-Request: golang/go#60473
---
M src/os/file.go
1 file changed, 5 insertions(+), 4 deletions(-)
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Rob Pike, Russ Cox.
Gerrit Bot uploaded patch set #3 to this change.
os: ReadFile: don't check for re-allocation in the first iteration
At the beginning of the for-loop iteration size > 0 always. so in
the first iteration, this check is not necessary. we can move this check to
after the read operation.
besides this change >= operator also can be simplified to == in the if-statement
Change-Id: I205e4a842ced74f31124b45a39b70523b56ad840
GitHub-Last-Rev: 2fdf25dff2e9984d3a8f8e5e612ea802c88e88a1
GitHub-Pull-Request: golang/go#60473
---
M src/os/file.go
1 file changed, 5 insertions(+), 4 deletions(-)
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Rob Pike, Russ Cox.
Gerrit Bot uploaded patch set #4 to this change.
os: ReadFile: don't check for re-allocation in the first iteration
At the beginning of the for-loop iteration cap(data) > len(data) always.
Therefore, in the first iteration, this check becomes unnecessary.
we can move this check to after the read operation.
Change-Id: I205e4a842ced74f31124b45a39b70523b56ad840
GitHub-Last-Rev: 2fdf25dff2e9984d3a8f8e5e612ea802c88e88a1
GitHub-Pull-Request: golang/go#60473
---
M src/os/file.go
1 file changed, 5 insertions(+), 4 deletions(-)
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Russ Cox.
Patch set 4:Run-TryBot +1
Attention is currently required from: Ian Lance Taylor, Russ Cox.
Patch set 4:Run-TryBot +1Auto-Submit +1Code-Review +2
1 comment:
Patchset:
Thanks.
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Russ Cox.
Patch set 4:-Auto-Submit-Code-Review
1 comment:
Patchset:
Sorry, at this point this should wait for 1.22.
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Ian Lance Taylor, Russ Cox.
1 comment:
Patchset:
Sorry, at this point this should wait for 1.22.
Thanks!
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Ian Lance Taylor, Russ Cox.
Patch set 4:Code-Review +2
1 comment:
Patchset:
Not your fault, as you're just rearranging existing pieces, but that loop is too tricky for my taste.
But that's an issue for another day.
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor, Ian Lance Taylor, Russ Cox.
Patch set 4:Code-Review +1
Attention is currently required from: Ian Lance Taylor, Russ Cox.
Patch set 4:Auto-Submit +1Code-Review +2
1 comment:
Patchset:
Thanks.
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.
Gopher Robot submitted this change.
os: ReadFile: don't check for re-allocation in the first iteration
At the beginning of the for-loop iteration cap(data) > len(data) always.
Therefore, in the first iteration, this check becomes unnecessary.
we can move this check to after the read operation.
Change-Id: I205e4a842ced74f31124b45a39b70523b56ad840
GitHub-Last-Rev: 2fdf25dff2e9984d3a8f8e5e612ea802c88e88a1
GitHub-Pull-Request: golang/go#60473
Reviewed-on: https://go-review.googlesource.com/c/go/+/498915
Reviewed-by: Rob Pike <r...@golang.org>
Reviewed-by: Bryan Mills <bcm...@google.com>
Run-TryBot: Rob Pike <r...@golang.org>
TryBot-Result: Gopher Robot <go...@golang.org>
Run-TryBot: Ian Lance Taylor <ia...@google.com>
Reviewed-by: Ian Lance Taylor <ia...@google.com>
Auto-Submit: Ian Lance Taylor <ia...@google.com>
---
M src/os/file.go
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/os/file.go b/src/os/file.go
index 806c1f2..2f12c3b 100644
--- a/src/os/file.go
+++ b/src/os/file.go
@@ -725,10 +725,6 @@
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 {
@@ -737,6 +733,11 @@
}
return data, err
}
+
+ if len(data) >= cap(data) {
+ d := append(data[:cap(data)], 0)
+ data = d[:len(data)]
+ }
}
}
To view, visit change 498915. To unsubscribe, or for help writing mail filters, visit settings.