mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Add ReadFrom and WriteTo methods to bytes.Buffer, to enable i/o without buffer allocation.
Use them in Copy and Copyn. Speed up ReadFile by using ReadFrom and avoiding Copy altogether (a minor win). R=rsc, gri CC=golang-dev https://golang.org/cl/166041
This commit is contained in:
parent
7e7008fa5e
commit
bc3e34759c
5 changed files with 194 additions and 5 deletions
|
|
@ -240,3 +240,25 @@ func TestNil(t *testing.T) {
|
|||
t.Error("expcted <nil>; got %q", b.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestReadFrom(t *testing.T) {
|
||||
var buf Buffer;
|
||||
for i := 3; i < 30; i += 3 {
|
||||
s := fillBytes(t, "TestReadFrom (1)", &buf, "", 5, bytes[0:len(bytes)/i]);
|
||||
var b Buffer;
|
||||
b.ReadFrom(&buf);
|
||||
empty(t, "TestReadFrom (2)", &b, s, make([]byte, len(data)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestWriteTo(t *testing.T) {
|
||||
var buf Buffer;
|
||||
for i := 3; i < 30; i += 3 {
|
||||
s := fillBytes(t, "TestReadFrom (1)", &buf, "", 5, bytes[0:len(bytes)/i]);
|
||||
var b Buffer;
|
||||
buf.WriteTo(&b);
|
||||
empty(t, "TestReadFrom (2)", &b, s, make([]byte, len(data)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue