This is the mail archive of the java-patches@sourceware.cygnus.com 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]

[patch] java.io.File fixes and String.substring() optimization


This patch fixes a couple of buglets in java.io.File: getName()
shouldn't return the leading "/", and lastModified() had an  overflow
that caused it to return weird values. The former fix also prompted me
to check if String.substring() would do the right  thing if it was
called with (0, length) - it should probably return itself in this
situation (the spec says somewhere that strings  with equivalent content
can and should be the same object, right?), so I patched that too.

  [ bryce ]

ChangeLog:

1999-07-22  Bryce McKinlay  <bryce@albatross.co.nz>

 * java/lang/natString.cc (substring): optimize where substring is
 entire String.
 * java/io/File.java (getName): don't return separator with file name.
 * java/io/natFile.cc (attr): fix overflow.

patch:

Index: java/lang/natString.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natString.cc,v
retrieving revision 1.5
diff -u -r1.5 natString.cc
--- natString.cc 1999/04/21 13:50:39 1.5
+++ natString.cc 1999/07/23 02:59:40
@@ -687,6 +687,8 @@
 {
   if (beginIndex < 0 || endIndex > count || beginIndex > endIndex)
     JvThrow (new StringIndexOutOfBoundsException());
+  if (beginIndex == 0 && endIndex == count)
+    return this;
   jint newCount = endIndex - beginIndex;
   if (newCount <= 8)  // Optimization, mainly for GC.
     return JvNewString(JvGetStringChars(this) + beginIndex, newCount);
Index: java/io/File.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/File.java,v
retrieving revision 1.2
diff -u -r1.2 File.java
--- File.java 1999/05/12 14:41:17 1.2
+++ File.java 1999/07/23 02:59:40
@@ -108,9 +108,7 @@
   public String getName ()
   {
     int last = path.lastIndexOf(separatorChar);
-    if (last == -1)
-      last = 0;
-    return path.substring(last);
+    return path.substring(last + 1);
   }

   public String getParent ()
Index: java/io/natFile.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/natFile.cc,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 natFile.cc
--- natFile.cc 1999/04/07 14:52:36 1.1.1.1
+++ natFile.cc 1999/07/23 02:59:40
@@ -105,7 +105,7 @@
   JvAssert (query == MODIFIED || query == LENGTH);
   // FIXME: time computation is very POSIX-specific -- POSIX and Java
   // have the same Epoch.
-  return query == MODIFIED ? sb.st_mtime * 1000 : sb.st_size;
+  return query == MODIFIED ? (jlong)sb.st_mtime * 1000 : sb.st_size;
 #else
   // There's no good choice here.
   return 23;




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