[cp-patches] FYI: Fix bug in static Byte constructor

Andrew John Hughes gnu_andrew at member.fsf.org
Mon Apr 21 14:34:25 UTC 2008


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  <gnu_andrew at member.fsf.org>

        * 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: byte_bug-02.diff
Type: text/x-diff
Size: 579 bytes
Desc: not available
Url : http://developer.classpath.org/pipermail/classpath-patches/attachments/20080421/03c90419/attachment.diff 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://developer.classpath.org/pipermail/classpath-patches/attachments/20080421/03c90419/attachment.pgp 


More information about the Classpath-patches mailing list