From cfb9e118e020707842e6b5136b07f5ab149540c1 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 31 Aug 2011 03:23:30 +0200 Subject: DynamicLibraryBundle*: Use generics for better spec / Drop Iterator in favor for int/size() for less temp objects --- .../com/jogamp/common/os/DynamicLibraryBundle.java | 54 +++++++++------------- .../jogamp/common/os/DynamicLibraryBundleInfo.java | 6 +-- 2 files changed, 26 insertions(+), 34 deletions(-) (limited to 'src/java/com') diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java index 8e072fd..23e1714 100755 --- a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java +++ b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java @@ -28,7 +28,10 @@ package com.jogamp.common.os; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; import com.jogamp.common.jvm.JNILibLoaderBase; @@ -55,18 +58,18 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { private DynamicLibraryBundleInfo info; - private List/*>*/ toolLibNames; + private List> toolLibNames; private boolean[] toolLibLoaded; private int toolLibLoadedNumber; - protected List/**/ nativeLibraries; + protected List nativeLibraries; - private List/**/ glueLibNames; + private List glueLibNames; private boolean[] glueLibLoaded; private int glueLibLoadedNumber; private long toolGetProcAddressHandle; - private HashSet toolGetProcAddressFuncNameSet; - private List toolGetProcAddressFuncNameList; + private HashSet toolGetProcAddressFuncNameSet; + private List toolGetProcAddressFuncNameList; public DynamicLibraryBundle(DynamicLibraryBundleInfo info) { if(null==info) { @@ -77,16 +80,16 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { System.err.println(Thread.currentThread().getName()+" - DynamicLibraryBundle.init start with: "+info.getClass().getName()); Thread.dumpStack(); } - nativeLibraries = new ArrayList(); + nativeLibraries = new ArrayList(); toolLibNames = info.getToolLibNames(); glueLibNames = info.getGlueLibNames(); loadLibraries(); toolGetProcAddressFuncNameList = info.getToolGetProcAddressFuncNameList(); if(null!=toolGetProcAddressFuncNameList) { - toolGetProcAddressFuncNameSet = new HashSet(toolGetProcAddressFuncNameList); + toolGetProcAddressFuncNameSet = new HashSet(toolGetProcAddressFuncNameList); toolGetProcAddressHandle = getToolGetProcAddressHandle(); } else { - toolGetProcAddressFuncNameSet = new HashSet(); + toolGetProcAddressFuncNameSet = new HashSet(); toolGetProcAddressHandle = 0; } if(DEBUG) { @@ -166,8 +169,8 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { return 0; } long aptr = 0; - for(Iterator iter=toolGetProcAddressFuncNameList.iterator(); 0==aptr && iter.hasNext(); ) { - String name = (String) iter.next(); + for (int i=0; i < toolGetProcAddressFuncNameList.size(); i++) { + final String name = toolGetProcAddressFuncNameList.get(i); aptr = dynamicLookupFunctionOnLibs(name); if(DEBUG) { System.err.println("getToolGetProcAddressHandle: "+name+" -> 0x"+Long.toHexString(aptr)); @@ -176,9 +179,9 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { return aptr; } - protected NativeLibrary loadFirstAvailable(List/**/ libNames, ClassLoader loader, boolean global) { - for (Iterator iter = libNames.iterator(); iter.hasNext(); ) { - NativeLibrary lib = NativeLibrary.open((String) iter.next(), loader, global); + protected NativeLibrary loadFirstAvailable(List libNames, ClassLoader loader, boolean global) { + for (int i=0; i < libNames.size(); i++) { + final NativeLibrary lib = NativeLibrary.open(libNames.get(i), loader, global); if (lib != null) { return lib; } @@ -216,18 +219,8 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { ClassLoader loader = getClass().getClassLoader(); NativeLibrary lib = null; - i=0; - for(Iterator iter = toolLibNames.iterator(); iter.hasNext(); i++) { - Object listObj = iter.next(); - List/**/ libNames = null; - if(listObj instanceof List) { - libNames = (List) listObj; - } else if(listObj instanceof String) { - libNames = new ArrayList(); - libNames.add((String)listObj); - } else { - throw new RuntimeException("List element "+i+" must be either a List or String: "+toolLibNames); - } + for (i=0; i < toolLibNames.size(); i++) { + final List libNames = toolLibNames.get(i); if( null != libNames && libNames.size() > 0 ) { lib = loadFirstAvailable(libNames, loader, info.shallLinkGlobal()); if ( null == lib ) { @@ -252,9 +245,8 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { } glueLibLoadedNumber = 0; - i=0; - for(Iterator iter = glueLibNames.iterator(); iter.hasNext(); i++) { - String libName = (String) iter.next(); + for (i=0; i < glueLibNames.size(); i++) { + final String libName = glueLibNames.get(i); boolean ignoreError = true; boolean res; try { @@ -291,8 +283,8 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { addr = NativeLibrary.dynamicLookupFunctionGlobal(funcName); } // Look up this function name in all known libraries - for (Iterator iter = nativeLibraries.iterator(); 0==addr && iter.hasNext(); ) { - lib = (NativeLibrary) iter.next(); + for (int i=0; 0==addr && i < nativeLibraries.size(); i++) { + lib = nativeLibraries.get(i); addr = lib.dynamicLookupFunction(funcName); } if(DEBUG_LOOKUP) { diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java b/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java index 081bac8..ca486bf 100644 --- a/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java +++ b/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java @@ -40,7 +40,7 @@ public interface DynamicLibraryBundleInfo { *
  • Cg/CgGL example: [ [ "libCg.so", "Cg" ], [ "libCgGL.so", "CgGL" ] ]
  • * */ - public List getToolLibNames(); + public List> getToolLibNames(); /** @return a list of Glue library names.
    *
      @@ -51,14 +51,14 @@ public interface DynamicLibraryBundleInfo { * Only the last entry is crucial, ie all other are optional preload dependencies and may generate errors, * which are ignored. */ - public List/**/ getGlueLibNames(); + public List getGlueLibNames(); /** May return the native libraries
      GetProcAddressFunc
      names, the first found function is being used.
      * This could be eg:
       glXGetProcAddressARB, glXGetProcAddressARB 
      .
      * If your Tool does not has this facility, just return null. * @see #toolGetProcAddress(long, String) */ - public List getToolGetProcAddressFuncNameList() ; + public List getToolGetProcAddressFuncNameList() ; /** May implement the lookup function using the Tools facility.
      * The actual function pointer is provided to allow proper bootstrapping of the ProcAddressTable, -- cgit v1.2.3