]> gcc.gnu.org Git - gcc.git/commitdiff
GNU Classpath merge.
authorMark Wielaard <mark@gcc.gnu.org>
Sun, 3 Nov 2002 20:27:31 +0000 (20:27 +0000)
committerMark Wielaard <mark@gcc.gnu.org>
Sun, 3 Nov 2002 20:27:31 +0000 (20:27 +0000)
2002-10-31  Stephen Crawley  <crawley@dstc.edu.au>

* java/lang/Double.java (valueOf): Return new Double(parseDouble(s)).

2002-10-31  Wu Gansha <gansha.wu@intel.com>:

        * java/util/ArrayList.java (readObject, writeObject): Only read/write
        size items.

2002-10-31  Wu Gansha <gansha.wu@intel.com>:

        * java/io/DataInputStream.java (convertFromUTF): Give StringBuffer an
        initial estimated size to avoid enlarge buffer frequently.

2002-10-31  Wu Gansha <gansha.wu@intel.com>:

* java/lang/reflect/Proxy.java (ProxyType): Set loader to System
ClassLoader when null.
(ProxyType.hashCode): Loader null check no longer needed.
(ProxyType.sameTypes): New method.
(ProxyType.equals): Use new method.

2002-10-31  Mark Wielaard  <mark@klomp.org>

        * java/net/URLDecoder.java (decode): Initialize Stringbuffer size to
length of String.
* java/net/URLEncoder.java (encode): Likewise.

2002-10-31  Mark Wielaard  <mark@klomp.org>

* java/util/zip/ZipInputStream.java (getNextEntry): Throw IOException
when stream is closed.
(closeEntry): Likewise.
(read): Likewise.
* java/util/zip/ZipOutputStream.java (putNextEntry): Throw
ZipException when no entry active.
(closeEntry): Likewise.
(write): Likewise.

From-SVN: r58772

libjava/ChangeLog
libjava/java/io/DataInputStream.java
libjava/java/lang/Double.java
libjava/java/lang/reflect/Proxy.java
libjava/java/net/URLDecoder.java
libjava/java/net/URLEncoder.java
libjava/java/util/ArrayList.java
libjava/java/util/zip/ZipInputStream.java
libjava/java/util/zip/ZipOutputStream.java

index f78a70035081f2e473a092aba36c7e79b4427eab..24820d84019e0a65943b79ccc87522ed86901a6e 100644 (file)
@@ -1,3 +1,42 @@
+2002-10-31  Stephen Crawley  <crawley@dstc.edu.au>
+
+       * java/lang/Double.java (valueOf): Return new Double(parseDouble(s)).
+
+2002-10-31  Wu Gansha <gansha.wu@intel.com>:
+
+        * java/util/ArrayList.java (readObject, writeObject): Only read/write
+        size items.
+
+2002-10-31  Wu Gansha <gansha.wu@intel.com>:
+
+        * java/io/DataInputStream.java (convertFromUTF): Give StringBuffer an
+        initial estimated size to avoid enlarge buffer frequently.
+
+2002-10-31  Wu Gansha <gansha.wu@intel.com>:
+
+       * java/lang/reflect/Proxy.java (ProxyType): Set loader to System
+       ClassLoader when null.
+       (ProxyType.hashCode): Loader null check no longer needed.
+       (ProxyType.sameTypes): New method.
+       (ProxyType.equals): Use new method.
+
+2002-10-31  Mark Wielaard  <mark@klomp.org>
+
+        * java/net/URLDecoder.java (decode): Initialize Stringbuffer size to
+       length of String.
+       * java/net/URLEncoder.java (encode): Likewise.
+
+2002-10-31  Mark Wielaard  <mark@klomp.org>
+
+       * java/util/zip/ZipInputStream.java (getNextEntry): Throw IOException
+       when stream is closed.
+       (closeEntry): Likewise.
+       (read): Likewise.
+       * java/util/zip/ZipOutputStream.java (putNextEntry): Throw
+       ZipException when no entry active.
+       (closeEntry): Likewise.
+       (write): Likewise.
+
 2002-11-02  Tom Tromey  <tromey@redhat.com>
 
        * java/lang/Class.h: Move JV_STATE_ERROR before JV_STATE_DONE.
index 1223e3e7fe5d838992a24844950c4f65420a441d..52c0c7a7b82bfe0b7a71da62238cd32253bac988 100644 (file)
@@ -734,7 +734,9 @@ public class DataInputStream extends FilterInputStream implements DataInput
   static String convertFromUTF(byte[] buf) 
     throws EOFException, UTFDataFormatException
   {
-    StringBuffer strbuf = new StringBuffer();
+    // Give StringBuffer an initial estimated size to avoid 
+    // enlarge buffer frequently
+    StringBuffer strbuf = new StringBuffer(buf.length/2 + 2);
 
     for (int i = 0; i < buf.length; )
       {
index 22f2b5f524a4ba2fc5343a00d6f1cdf9912c58a2..199f64ee5b888caf4bcf11768dc750c823e81fa5 100644 (file)
@@ -191,10 +191,7 @@ public final class Double extends Number implements Comparable
    */
   public static Double valueOf(String s)
   {
-    // XXX just call new Double(parseDouble(s));
-    if (s == null)
-      throw new NullPointerException();
-    return new Double(s);
+    return new Double(parseDouble(s));
   }
 
   /**
index 972ac19c37ac3449cc67be470c000358b8a26fe5..82cf3722263d5fa899ac9789d3cd7e9d87035003 100644 (file)
@@ -462,7 +462,6 @@ public class Proxy implements Serializable
   private static native Class generateProxyClass0(ClassLoader loader,
                                                   ProxyData data);
 
-\f
   /**
    * Helper class for mapping unique ClassLoader and interface combinations
    * to proxy classes.
@@ -490,6 +489,8 @@ public class Proxy implements Serializable
      */
     ProxyType(ClassLoader loader, Class[] interfaces)
     {
+      if (loader == null)
+         loader = ClassLoader.getSystemClassLoader();
       this.loader = loader;
       this.interfaces = interfaces;
     }
@@ -501,12 +502,56 @@ public class Proxy implements Serializable
      */
     public int hashCode()
     {
-      int hash = (loader == null) ? 0 : loader.hashCode();
+      //loader is always not null
+      int hash = loader.hashCode();
       for (int i = 0; i < interfaces.length; i++)
         hash = hash * 31 + interfaces[i].hashCode();
       return hash;
     }
 
+    // A more comprehensive comparison of two arrays,
+    //   ignore array element order, and
+    //   ignore redundant elements
+    private static boolean sameTypes(Class arr1[], Class arr2[]) {
+      if (arr1.length == 1 && arr2.length == 1) {
+        return arr1[0] == arr2[0];
+      }
+        
+      // total occurrance of elements of arr1 in arr2
+      int total_occ_of_arr1_in_arr2 = 0;
+    each_type:
+      for (int i = arr1.length; --i >= 0; ) 
+      {
+        Class t = arr1[i];
+        for (int j = i; --j >= 0; ) 
+        {
+          if (t == arr1[j]) 
+          { //found duplicate type
+            continue each_type;  
+          }
+        }
+            
+        // count c(a unique element of arr1)'s 
+        //   occurrences in arr2
+        int occ_in_arr2 = 0;
+        for (int j = arr2.length; --j >= 0; ) 
+        {
+          if (t == arr2[j]) 
+          {
+            ++occ_in_arr2;
+          }
+        }
+        if (occ_in_arr2 == 0) 
+        { // t does not occur in arr2
+          return false;
+        }
+        
+        total_occ_of_arr1_in_arr2 += occ_in_arr2;
+      }
+      // now, each element of arr2 must have been visited
+      return total_occ_of_arr1_in_arr2 == arr2.length;
+    }
+
     /**
      * Calculates equality.
      *
@@ -518,15 +563,10 @@ public class Proxy implements Serializable
       ProxyType pt = (ProxyType) other;
       if (loader != pt.loader || interfaces.length != pt.interfaces.length)
         return false;
-      int i = interfaces.length;
-      while (--i >= 0)
-        if (interfaces[i] != pt.interfaces[i])
-          return false;
-      return true;
+         return sameTypes(interfaces, pt.interfaces);
     }
   } // class ProxyType
 
-\f
   /**
    * Helper class which allows hashing of a method name and signature
    * without worrying about return type, declaring class, or throws clause,
@@ -681,7 +721,6 @@ public class Proxy implements Serializable
     }
   } // class ProxySignature
 
-\f
   /**
    * A flat representation of all data needed to generate bytecode/instantiate
    * a proxy class.  This is basically a struct.
@@ -820,7 +859,6 @@ public class Proxy implements Serializable
     }
   } // class ProxyData
 
-\f
   /**
    * Does all the work of building a class. By making this a nested class,
    * this code is not loaded in memory if the VM has a native
index 8cdcf94382589821c23ba630e59453a56208b47f..36747409983edc221edb97a510dfbb1cb7d06b38 100644 (file)
@@ -63,7 +63,7 @@ import java.io.UnsupportedEncodingException;
 public class URLDecoder
 {
   /**
-   * Constructor for compatibility with Sun's JDK.
+   * Public contructor. Note that this class has only static methods.
    */
   public URLDecoder ()
   {
@@ -116,8 +116,6 @@ public class URLDecoder
   public static String decode(String s, String encoding)
     throws UnsupportedEncodingException
   {
-    StringBuffer result = new StringBuffer();
-
     // First convert all '+' characters to spaces.
     String str = s.replace('+', ' ');
     
@@ -126,6 +124,7 @@ public class URLDecoder
     int start = 0;
     byte[] bytes = null;
     int length = str.length();
+    StringBuffer result = new StringBuffer(length);
     while ((i = str.indexOf('%', start)) >= 0)
       {
        // Add all non-encoded characters to the result buffer
index 345ef2404d5063db822a450159c38c945d561c46..0f106e820de64bc527b72120c5ac13451d3fbf30 100644 (file)
@@ -1,5 +1,5 @@
 /* URLEncoder.java -- Class to convert strings to a properly encoded URL
-   Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -39,7 +39,7 @@ package java.net;
 
 import java.io.UnsupportedEncodingException;
 
-/**
+/*
  * Written using on-line Java Platform 1.2/1.4 API Specification, as well
  * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
  * Status:  Believed complete and correct.
@@ -102,11 +102,11 @@ public class URLEncoder
   public static String encode(String s, String encoding)
     throws UnsupportedEncodingException
   {
-    StringBuffer result = new StringBuffer();
     int length = s.length();
     int start = 0;
     int i = 0;
 
+    StringBuffer result = new StringBuffer(length);
     while (true)
     {
       while ( i < length && isSafe(s.charAt(i)) )
index 2d2146ddf595afca5d195e2a781fe53d76680010..c6f6b86991df5f1424c598923dc84aeb816f2dbe 100644 (file)
@@ -558,7 +558,9 @@ public class ArrayList extends AbstractList
     // We serialize unused list entries to preserve capacity.
     int len = data.length;
     s.writeInt(len);
-    for (int i = 0; i < len; i++)
+    // it would be more efficient to just write "size" items,
+    // this need readObject read "size" items too.
+    for (int i = 0; i < size; i++)
       s.writeObject(data[i]);
   }
 
@@ -578,7 +580,7 @@ public class ArrayList extends AbstractList
     s.defaultReadObject();
     int capacity = s.readInt();
     data = new Object[capacity];
-    for (int i = 0; i < capacity; i++)
+    for (int i = 0; i < size; i++)
       data[i] = s.readObject();
   }
 }
index 710ca74c201893d6de5d72dd202a6b3644b4c0eb..c9a6c0159e7c85a1d65e1e68d9a8c9715b2b6164 100644 (file)
@@ -139,7 +139,7 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
   public ZipEntry getNextEntry() throws IOException
   {
     if (crc == null)
-      throw new IllegalStateException("Closed.");
+      throw new IOException("Stream closed.");
     if (entry != null)
       closeEntry();
 
@@ -216,7 +216,7 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
   public void closeEntry() throws IOException
   {
     if (crc == null)
-      throw new IllegalStateException("Closed.");
+      throw new IOException("Stream closed.");
     if (entry == null)
       return;
 
@@ -287,7 +287,7 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
   public int read(byte[] b, int off, int len) throws IOException
   {
     if (crc == null)
-      throw new IllegalStateException("Closed.");
+      throw new IOException("Stream closed.");
     if (entry == null)
       return -1;
     boolean finished = false;
index e4fb864a95536612132c259651054bb89b03b796..44c4a9cc9b138288acf95ad98bd7b197c10533e8 100644 (file)
@@ -158,12 +158,12 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
    * is not set in the entry, the current time is used.
    * @param entry the entry.
    * @exception IOException if an I/O error occured.
-   * @exception IllegalStateException if stream was finished
+   * @exception ZipException if stream was finished.
    */
   public void putNextEntry(ZipEntry entry) throws IOException
   {
     if (entries == null)
-      throw new IllegalStateException("ZipOutputStream was finished");
+      throw new ZipException("ZipOutputStream was finished");
 
     int method = entry.getMethod();
     int flags = 0;
@@ -249,12 +249,12 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
   /**
    * Closes the current entry.
    * @exception IOException if an I/O error occured.
-   * @exception IllegalStateException if no entry is active.
+   * @exception ZipException if no entry is active.
    */
   public void closeEntry() throws IOException
   {
     if (curEntry == null)
-      throw new IllegalStateException("No open entry");
+      throw new ZipException("No open entry");
 
     /* First finish the deflater, if appropriate */
     if (curMethod == DEFLATED)
@@ -300,12 +300,12 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
   /**
    * Writes the given buffer to the current entry.
    * @exception IOException if an I/O error occured.
-   * @exception IllegalStateException if no entry is active.
+   * @exception ZipException if no entry is active.
    */
   public void write(byte[] b, int off, int len) throws IOException
   {
     if (curEntry == null)
-      throw new IllegalStateException("No open entry.");
+      throw new ZipException("No open entry.");
 
     switch (curMethod)
       {
This page took 0.086839 seconds and 5 git commands to generate.