This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: java.io.LineNumberReader


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


The non-working non-merged skip() method of java.io.LineNumberReader 
really annoyed me enough to make me writing a patch for it.

The line number incrementation is already done in read() of 
LineNumberReader so we dont need to do this in skip() too.
In the original versions line counting was just wrong when using 
skip().

Please review the attached patch and comment.

Okay for commit ? Okay for 3.3 too ?

Is a similar patch for classpath okay too to make both versions 
merged?


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+9KgZWSOgCCdjSDsRAi4MAJ98JdFog95+yLMTzljyqI2MgIN0aACdEKyP
t4zHm4ZpyXbyuMzdUXc0ypQ=
=eIof
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1980
diff -u -b -B -r1.1980 ChangeLog
--- ChangeLog	21 Jun 2003 17:06:56 -0000	1.1980
+++ ChangeLog	21 Jun 2003 18:42:43 -0000
@@ -1,5 +1,11 @@
 2003-06-21  Michael Koch  <konqueror@gmx.de>
 
+	* java/io/LineNumberReader.java
+	(skip): Dont do line number accounting here as this is already done in
+	read(), simplified.
+
+2003-06-21  Michael Koch  <konqueror@gmx.de>
+
 	* java/io/File.java
 	(static): Load javaio lib if existing (only in classpath).
 	(File): Revised documentation to show the correct argument name.
Index: java/io/LineNumberReader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/LineNumberReader.java,v
retrieving revision 1.8
diff -u -b -B -r1.8 LineNumberReader.java
--- java/io/LineNumberReader.java	24 Mar 2003 15:43:22 -0000	1.8
+++ java/io/LineNumberReader.java	21 Jun 2003 18:42:43 -0000
@@ -374,37 +374,22 @@
     *
     * @exception IOException If an error occurs
     */
-  public long skip(long count) throws IOException
+  public long skip (long count) throws IOException
   {
     if (count <= 0)
       return 0;
-    long to_do = count;
-    do
+
+    int skipped;
+    
+    for (skipped = 0; skipped < count; skipped++)
       {
 	int ch = read();
+
 	if (ch < 0)
 	  break;
-	to_do--;
-	if (ch == '\n' || ch == '\r')
-	  lineNumber++;
-	else
-	  {
-	    long fence = pos + to_do;
-	    if (limit < fence)
-	      fence = limit;
-	    int end = pos;
-	    for (; end < fence; end++)
-	      {
-		char endch = buffer[end];
-		if (endch == '\n' || endch == '\r')
-		  break;
-	      }
-	    to_do -= end - pos;
-	    pos = end;
-	  }
       }
-    while (to_do > 0);
-    return count - to_do;
+
+    return skipped;
   }
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]