Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1486)

Delta Between Two Patch Sets: src/pkg/io/io.go

Issue 9462044: code review 9462044: io: Prioritize WriterTos over ReaderFroms in Copy. (Closed)
Left Patch Set: diff -r 4e860d4a312b https://code.google.com/p/go/ Created 10 years, 10 months ago
Right Patch Set: diff -r 0fb55e40bd0c https://code.google.com/p/go/ Created 10 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/io/io_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Package io provides basic interfaces to I/O primitives. 5 // Package io provides basic interfaces to I/O primitives.
6 // Its primary job is to wrap existing implementations of such primitives, 6 // Its primary job is to wrap existing implementations of such primitives,
7 // such as those in package os, into shared public interfaces that 7 // such as those in package os, into shared public interfaces that
8 // abstract the functionality, plus some other related primitives. 8 // abstract the functionality, plus some other related primitives.
9 // 9 //
10 // Because these interfaces and primitives wrap lower-level operations with 10 // Because these interfaces and primitives wrap lower-level operations with
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 322 }
323 323
324 // Copy copies from src to dst until either EOF is reached 324 // Copy copies from src to dst until either EOF is reached
325 // on src or an error occurs. It returns the number of bytes 325 // on src or an error occurs. It returns the number of bytes
326 // copied and the first error encountered while copying, if any. 326 // copied and the first error encountered while copying, if any.
327 // 327 //
328 // A successful Copy returns err == nil, not err == EOF. 328 // A successful Copy returns err == nil, not err == EOF.
329 // Because Copy is defined to read from src until EOF, it does 329 // Because Copy is defined to read from src until EOF, it does
330 // not treat an EOF from Read as an error to be reported. 330 // not treat an EOF from Read as an error to be reported.
331 // 331 //
332 // If dst implements the ReaderFrom interface, 332 // If src implements the WriterTo interface,
333 // the copy is implemented by calling src.WriteTo(dst).
334 // Otherwise, if dst implements the ReaderFrom interface,
333 // the copy is implemented by calling dst.ReadFrom(src). 335 // the copy is implemented by calling dst.ReadFrom(src).
334 // Otherwise, if src implements the WriterTo interface,
remyoudompheng 2013/05/20 20:37:36 the documentation is now incorrect.
DMorsing 2013/05/20 21:01:43 Done.
335 // the copy is implemented by calling src.WriteTo(dst).
336 func Copy(dst Writer, src Reader) (written int64, err error) { 336 func Copy(dst Writer, src Reader) (written int64, err error) {
337 // If the reader has a WriteTo method, use it to do the copy. 337 // If the reader has a WriteTo method, use it to do the copy.
338 // Avoids an allocation and a copy. 338 // Avoids an allocation and a copy.
339 if wt, ok := src.(WriterTo); ok { 339 if wt, ok := src.(WriterTo); ok {
340 return wt.WriteTo(dst) 340 return wt.WriteTo(dst)
341 } 341 }
342 // Similarly, if the writer has a ReadFrom method, use it to do the copy . 342 // Similarly, if the writer has a ReadFrom method, use it to do the copy .
343 if rt, ok := dst.(ReaderFrom); ok { 343 if rt, ok := dst.(ReaderFrom); ok {
344 return rt.ReadFrom(src) 344 return rt.ReadFrom(src)
345 } 345 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 479
480 func (t *teeReader) Read(p []byte) (n int, err error) { 480 func (t *teeReader) Read(p []byte) (n int, err error) {
481 n, err = t.r.Read(p) 481 n, err = t.r.Read(p)
482 if n > 0 { 482 if n > 0 {
483 if n, err := t.w.Write(p[:n]); err != nil { 483 if n, err := t.w.Write(p[:n]); err != nil {
484 return n, err 484 return n, err
485 } 485 }
486 } 486 }
487 return 487 return
488 } 488 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b