Explorar el Código

reallocate in for loop

Darien Raymond hace 8 años
padre
commit
afcad409e2
Se han modificado 1 ficheros con 4 adiciones y 4 borrados
  1. 4 4
      common/buf/writer.go

+ 4 - 4
common/buf/writer.go

@@ -60,12 +60,12 @@ func (w *BufferedWriter) Write(b []byte) (int, error) {
 		return w.legacyWriter.Write(b)
 	}
 
-	if w.buffer == nil {
-		w.buffer = New()
-	}
-
 	totalBytes := 0
 	for len(b) > 0 {
+		if w.buffer == nil {
+			w.buffer = New()
+		}
+
 		nBytes, err := w.buffer.Write(b)
 		totalBytes += nBytes
 		if err != nil {