On Monday 21 April 2008 12:09:16 Christian Thalinger wrote:
> On Mon, 2008-04-21 at 11:43 +0100, Andrew Haley wrote:
> > Why use a short and not an int?
> >
> >     for (int i=MIN_VALUE; i <= MAX_VALUE; i++)
> >
> > would be more idiomatic and faster on many targets.
>
> Same as I suggested.  This would also apply to:
>
> --- java/lang/Character.java    19 Dec 2006 01:14:23 -0000      1.48
> +++ java/lang/Character.java    14 Apr 2008 13:54:25 -0000
> @@ -2055,6 +2055,11 @@
>    // this constant controls how much we actually cache.
>    private static final int MAX_CACHE = 127;
>    private static Character[] charCache = new Character[MAX_CACHE + 1];
> +  static
> +  {
> +     for (char i=0; i <= MAX_CACHE; i++)
> +       charCache[i] = new Character(i);
> +  }
>
> --- java/lang/Short.java        10 Dec 2006 20:25:44 -0000      1.20
> +++ java/lang/Short.java        14 Apr 2008 13:54:25 -0000
> @@ -90,6 +90,11 @@
>    private static final int MIN_CACHE = -128;
>    private static final int MAX_CACHE = 127;
>    private static Short[] shortCache = new Short[MAX_CACHE - MIN_CACHE +
> 1]; +  static
> +  {
> +    for (short i=MIN_CACHE; i <= MAX_CACHE; i++)
> +      shortCache[i - MIN_CACHE] = new Short(i);
> +  }
>
> - twisti

Indeed you did suggest it, but didn't give me a good reason to do it... ;)

Anyway, here's the patch to change to an int.  I haven't changed the other 
two, because it also means introducing a cast in the loop body.  If it's 
still worthwhile, given this, I'll add that too.

2008-04-21  Andrew John Hughes  <[EMAIL PROTECTED]>

        * java/lang/Byte.java:
        Use int instead of short as a loop counter
        for efficiency.


-- 
Andrew :)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint = F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8
Index: java/lang/Byte.java
===================================================================
RCS file: /sources/classpath/classpath/java/lang/Byte.java,v
retrieving revision 1.28
diff -u -r1.28 Byte.java
--- java/lang/Byte.java	21 Apr 2008 10:37:47 -0000	1.28
+++ java/lang/Byte.java	21 Apr 2008 14:25:02 -0000
@@ -90,7 +90,7 @@
   private static Byte[] byteCache = new Byte[MAX_VALUE - MIN_VALUE + 1];
   static
   {
-    for (short i=MIN_VALUE; i <= MAX_VALUE; i++)
+    for (int i=MIN_VALUE; i <= MAX_VALUE; i++)
       byteCache[i - MIN_VALUE] = new Byte((byte) i);
   }
 

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to