@@ -50,7 +50,7 @@ export func NewBufReadSize(rd io.Read, size int) (b *BufRead, err *os.Error) {
5050 if size <= 0 {
5151 return nil , BadBufSize
5252 }
53- b = new (BufRead );
53+ b = new (* BufRead );
5454 b .buf = new ([]byte , size );
5555 b .rd = rd ;
5656 return b , nil
@@ -191,11 +191,9 @@ func (b *BufRead) Buffered() int {
191191// For internal (or advanced) use only.
192192// Use ReadLineString or ReadLineBytes instead.
193193
194- var NIL []byte // TODO(rsc): should be able to use nil
195-
196194func (b * BufRead ) ReadLineSlice (delim byte ) (line []byte , err * os.Error ) {
197195 if b .err != nil {
198- return NIL , b .err
196+ return nil , b .err
199197 }
200198
201199 // Look in buffer.
@@ -210,7 +208,7 @@ func (b *BufRead) ReadLineSlice(delim byte) (line []byte, err *os.Error) {
210208 n := b .Buffered ();
211209 b .Fill ();
212210 if b .err != nil {
213- return NIL , b .err
211+ return nil , b .err
214212 }
215213 if b .Buffered () == n { // no data added; end of file
216214 line := b .buf [b .r :b .w ];
@@ -227,12 +225,12 @@ func (b *BufRead) ReadLineSlice(delim byte) (line []byte, err *os.Error) {
227225
228226 // Buffer is full?
229227 if b .Buffered () >= len (b .buf ) {
230- return NIL , BufferFull
228+ return nil , BufferFull
231229 }
232230 }
233231
234232 // BUG 6g bug100
235- return NIL , nil
233+ return nil , nil
236234}
237235
238236// Read until the first occurrence of delim in the input,
@@ -242,7 +240,7 @@ func (b *BufRead) ReadLineSlice(delim byte) (line []byte, err *os.Error) {
242240// we might have read more than the buffer size.)
243241func (b * BufRead ) ReadLineBytes (delim byte ) (line []byte , err * os.Error ) {
244242 if b .err != nil {
245- return NIL , b .err
243+ return nil , b .err
246244 }
247245
248246 // Use ReadLineSlice to look for array,
@@ -279,7 +277,7 @@ func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
279277 }
280278
281279 // Grow list if needed.
282- if len ( full ) == 0 {
280+ if full == nil {
283281 full = new ([][]byte , 16 );
284282 } else if nfull >= len (full ) {
285283 newfull := new ([][]byte , len (full )* 2 );
@@ -313,26 +311,18 @@ func (b *BufRead) ReadLineBytes(delim byte) (line []byte, err *os.Error) {
313311 return buf , err
314312}
315313
316- // BUG(bugs/bug102.go): string(empty bytes array) throws error
317- func ToString (p []byte ) string {
318- if len (p ) == 0 {
319- return ""
320- }
321- return string (p )
322- }
323-
324314// Read until the first occurrence of delim in the input,
325315// returning a new string containing the line.
326316// If savedelim, keep delim in the result; otherwise chop it off.
327317func (b * BufRead ) ReadLineString (delim byte , savedelim bool ) (line string , err * os.Error ) {
328318 bytes , e := b .ReadLineBytes (delim );
329319 if e != nil {
330- return ToString (bytes ), e
320+ return string (bytes ), e
331321 }
332322 if ! savedelim {
333323 bytes = bytes [0 :len (bytes )- 1 ]
334324 }
335- return ToString (bytes ), nil
325+ return string (bytes ), nil
336326}
337327
338328
@@ -349,7 +339,7 @@ export func NewBufWriteSize(wr io.Write, size int) (b *BufWrite, err *os.Error)
349339 if size <= 0 {
350340 return nil , BadBufSize
351341 }
352- b = new (BufWrite );
342+ b = new (* BufWrite );
353343 b .buf = new ([]byte , size );
354344 b .wr = wr ;
355345 return b , nil
0 commit comments