classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Fixlet for DataInputStream.readLine


From: Roman Kennke
Subject: [cp-patches] FYI: Fixlet for DataInputStream.readLine
Date: Wed, 15 Jun 2005 17:20:46 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

I added an optimization to DataInputStream.readLine(). If this method needs to push back a character, it used to wrap the field in into a PushbackInputStream. This is not always necessary, especially in cases where in is an InputStream that supports the pos field for repositioning. I committed this.

2005-06-15  Roman Kennke  <address@hidden>

   * java/io/DataInputStream.java
   (readLine): Added checks for InputStream that support have a pos field
   for repositioning the stream.

/Roman
Index: java/io/DataInputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/DataInputStream.java,v
retrieving revision 1.28
diff -u -r1.28 DataInputStream.java
--- java/io/DataInputStream.java        7 Mar 2005 13:50:45 -0000       1.28
+++ java/io/DataInputStream.java        15 Jun 2005 14:41:37 -0000
@@ -361,9 +361,30 @@
            int next_c = in.read();
             if (next_c != '\n' && next_c != -1)
               {
-                if (! (in instanceof PushbackInputStream))
-                    in = new PushbackInputStream(in);
-                ((PushbackInputStream) in).unread(next_c);
+               if (in instanceof BufferedInputStream)
+                  {
+                       BufferedInputStream bin = (BufferedInputStream) in;
+                       if (bin.pos > 0)
+                      bin.pos--;
+                 }
+               else if (in instanceof StringBufferInputStream)
+                  {
+                       StringBufferInputStream bin = (StringBufferInputStream) 
in;
+                       if (bin.pos > 0)
+                      bin.pos--;
+                 }
+                else if (in instanceof ByteArrayInputStream)
+                  {
+                    ByteArrayInputStream bin = (ByteArrayInputStream) in;
+                    if (bin.pos > 0)
+                      bin.pos--;
+                  }
+                else
+                  {
+                    if (! (in instanceof PushbackInputStream))
+                      in = new PushbackInputStream(in);
+                    ((PushbackInputStream) in).unread(next_c);
+                  }
               }
             break;
          }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]