From 1c1ffed31548094cf7afbb4c83b0cb627ae3a1ad Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 9 Jun 2013 06:11:33 +0200 Subject: Bug 747: Allow usage of IdentityHashMap w/ keys: AbstractGraphicsDevice.getUniqueID() and GLContext.getDeviceVersionAvailableKey() .. both value classes unique, long lived and rare. --- src/jogl/classes/javax/media/opengl/GLContext.java | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/jogl/classes/javax') diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index abafabb1c..fd3c31b6d 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -42,7 +42,7 @@ package javax.media.opengl; import java.nio.IntBuffer; import java.util.HashMap; -import java.util.HashSet; +import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Set; @@ -1209,12 +1209,12 @@ public abstract class GLContext { /** * @see #getDeviceVersionAvailableKey(javax.media.nativewindow.AbstractGraphicsDevice, int, int) */ - protected static /*final*/ HashMap deviceVersionAvailable = new HashMap(); + protected static /*final*/ IdentityHashMap deviceVersionAvailable = new IdentityHashMap(); /** * @see #getUniqueDeviceString(javax.media.nativewindow.AbstractGraphicsDevice) */ - private static /*final*/ HashSet deviceVersionsAvailableSet = new HashSet(); + private static /*final*/ IdentityHashMap deviceVersionsAvailableSet = new IdentityHashMap(); /** clears the device/context mappings as well as the GL/GLX proc address tables. */ protected static void shutdown() { @@ -1225,17 +1225,16 @@ public abstract class GLContext { protected static boolean getAvailableGLVersionsSet(AbstractGraphicsDevice device) { synchronized ( deviceVersionsAvailableSet ) { - return deviceVersionsAvailableSet.contains(device.getUniqueID()); + return deviceVersionsAvailableSet.containsKey(device.getUniqueID()); } } protected static void setAvailableGLVersionsSet(AbstractGraphicsDevice device) { synchronized ( deviceVersionsAvailableSet ) { - String devKey = device.getUniqueID(); - if ( deviceVersionsAvailableSet.contains(devKey) ) { + final String devKey = device.getUniqueID(); + if( null != deviceVersionsAvailableSet.put(devKey, devKey) ) { throw new InternalError("Already set: "+devKey); } - deviceVersionsAvailableSet.add(devKey); if (DEBUG) { System.err.println(getThreadName() + ": createContextARB: SET mappedVersionsAvailableSet "+devKey); System.err.println(GLContext.dumpAvailableGLVersions(null).toString()); @@ -1243,8 +1242,13 @@ public abstract class GLContext { } } + /** + * Returns a unique String object using {@link String#intern()} for the given arguments, + * which object reference itself can be used as a key. + */ protected static String getDeviceVersionAvailableKey(AbstractGraphicsDevice device, int major, int profile) { - return device.getUniqueID() + "-" + toHexString(composeBits(major, profile, 0)); + final String r = device.getUniqueID() + "-" + toHexString(composeBits(major, profile, 0)); + return r.intern(); } /** @@ -1272,10 +1276,10 @@ public abstract class GLContext { System.err.println("GLContext.mapAvailableGLVersion: "+device+": "+getGLVersion(reqMajor, 0, profile, null)+" -> "+getGLVersion(resMajor, resMinor, resCtp, null)); // Thread.dumpStack(); } - final String key = getDeviceVersionAvailableKey(device, reqMajor, profile); + final String objectKey = getDeviceVersionAvailableKey(device, reqMajor, profile); final Integer val = new Integer(composeBits(resMajor, resMinor, resCtp)); synchronized(deviceVersionAvailable) { - return deviceVersionAvailable.put( key, val ); + return deviceVersionAvailable.put( objectKey, val ); } } @@ -1315,10 +1319,10 @@ public abstract class GLContext { * @return the available GL version as encoded with {@link #composeBits(int, int, int), otherwise null */ protected static Integer getAvailableGLVersion(AbstractGraphicsDevice device, int reqMajor, int reqProfile) { - String key = getDeviceVersionAvailableKey(device, reqMajor, reqProfile); + final String objectKey = getDeviceVersionAvailableKey(device, reqMajor, reqProfile); Integer val; synchronized(deviceVersionAvailable) { - val = deviceVersionAvailable.get( key ); + val = deviceVersionAvailable.get( objectKey ); } return val; } -- cgit v1.2.3