JDK-6832045 : DefaultSynthStyle.{getStateInfo,getMatchCount) should use Integer.bitCount
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-04-20
  • Updated: 2016-04-28
  • Resolved: 2016-04-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b116Fixed
Related Reports
Relates :  
Description
DefaultSynthStyle.getStateInfo and DefaultSynthStyle.getMatchCount actually duplicate the code of Integer.bitCount.  The suggested fix leads to better maintainability and can lead to better performance on architectures which support a population count instruction (see 6378821).

Comments
trivial cleanup
07-04-2016

My oldest open bug :-)
07-04-2016

SUGGESTED FIX --- jdk.22b6e09960c1/src/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java 2009-04-20 15:48:03.959953300 +0200 +++ /export/home/twisti/projects/openjdk/jdk7/tl/jdk/src/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java 2009-04-20 14:28:34.246603409 +0200 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2002-2009 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -645,16 +645,8 @@ public class DefaultSynthStyle extends S // StateInfo match, otherwise a StateInfo with // SELECTED | ENABLED would match ENABLED, which we // don't want. - - // This comes from BigInteger.bitCnt - int bitCount = oState; - bitCount -= (0xaaaaaaaa & bitCount) >>> 1; - bitCount = (bitCount & 0x33333333) + ((bitCount >>> 2) & - 0x33333333); - bitCount = bitCount + (bitCount >>> 4) & 0x0f0f0f0f; - bitCount += bitCount >>> 8; - bitCount += bitCount >>> 16; - bitCount = bitCount & 0xff; + + int bitCount = Integer.bitCount(oState); if (bitCount > bestCount) { bestIndex = counter; bestCount = bitCount; @@ -889,14 +881,7 @@ public class DefaultSynthStyle extends S * ComponentState this StateInfo represents and val. */ private int getMatchCount(int val) { - // This comes from BigInteger.bitCnt - val &= state; - val -= (0xaaaaaaaa & val) >>> 1; - val = (val & 0x33333333) + ((val >>> 2) & 0x33333333); - val = val + (val >>> 4) & 0x0f0f0f0f; - val += val >>> 8; - val += val >>> 16; - return val & 0xff; + return Integer.bitCount(state & val); } /**
20-04-2009