@@ -23,6 +23,7 @@ func (w *ByteWriter) Write(p []byte) (n int, err error) {
2323 bptr = AllocRegion (len (p ))
2424 w .b = bptr
2525 }
26+ // TODO: copy when cap(*bptr) < len(*bptr)+len(p)?
2627 // append may grow the slice beyond original capacity
2728 // and so, it may get recycled to a higher slab on Close
2829 * bptr = append (* bptr , p ... )
@@ -48,32 +49,32 @@ func (w *ByteWriter) Bytes() []byte {
4849}
4950
5051func (w * ByteWriter ) Copy () []byte {
51- if bptr := w .b ; bptr != nil {
52- bcopy := make ([]byte , len (* bptr ))
53- copy (bcopy , * bptr )
54- return bcopy
52+ if b := w .b ; b != nil {
53+ c := make ([]byte , len (* b ))
54+ copy (c , * b )
55+ return c
5556 }
5657 return nil
5758}
5859
5960func (w * ByteWriter ) Dup () ByteWriter {
60- if bptr := w .b ; bptr != nil {
61- bptr2 := AllocRegion (len (* bptr ))
62- copy (* bptr2 , * bptr )
63- return ByteWriter {b : bptr2 }
61+ if b := w .b ; b != nil {
62+ b2 := AllocRegion (len (* b ))
63+ copy (* b2 , * b )
64+ return ByteWriter {b : b2 }
6465 }
6566 return ByteWriter {}
6667}
6768
6869func (w * ByteWriter ) Len () int {
69- if bptr := w .b ; bptr != nil {
70- return len (* bptr )
70+ if b := w .b ; b != nil {
71+ return len (* b )
7172 }
7273 return 0
7374}
7475
7576func (w * ByteWriter ) Reset () {
76- if bptr := w .b ; bptr != nil {
77- * bptr = (* bptr )[:0 ]
77+ if b := w .b ; b != nil {
78+ * b = (* b )[:0 ]
7879 }
7980}
0 commit comments