From 6095ca5f799025883fdfa58a9c5f0ba7447ab1cd Mon Sep 17 00:00:00 2001
From: git <tdnorbra@nps.edu>
Date: Sat, 26 Oct 2024 06:26:03 -0600
Subject: [PATCH] [Terry N.] move object decl. out of loops

---
 .../web3d/vrml/renderer/CRProtoCreator.java   | 34 +++++++++++--------
 .../renderer/ogl/OGLExternPrototypeDecl.java  |  3 +-
 .../org/xj3d/core/loading/ContentLoader.java  | 18 +++++-----
 .../xj3d/core/loading/LoaderThreadPool.java   | 10 +++---
 4 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/src/java/org/web3d/vrml/renderer/CRProtoCreator.java b/src/java/org/web3d/vrml/renderer/CRProtoCreator.java
index bc14a873..aac5a861 100644
--- a/src/java/org/web3d/vrml/renderer/CRProtoCreator.java
+++ b/src/java/org/web3d/vrml/renderer/CRProtoCreator.java
@@ -351,13 +351,13 @@ public abstract class CRProtoCreator
      */
     private void processDEFs(Map<String, VRMLNode> defMappings) {
         Set<Entry<String, VRMLNode>> def_set = defMappings.entrySet();
-        Iterator<Entry<String, VRMLNode>> itr = def_set.iterator();
-
-        while(itr.hasNext()) {
-            Map.Entry<String, VRMLNode> e = itr.next();
-            String name = e.getKey();
-            VRMLNodeType src_node = (VRMLNodeType) e.getValue();
-            VRMLNodeType dest_node = (VRMLNodeType) nodeMap.get(src_node);
+        String name;
+        VRMLNodeType src_node;
+        VRMLNodeType dest_node;
+        for (Entry<String, VRMLNode> e : def_set) {
+            name = e.getKey();
+            src_node = (VRMLNodeType) e.getValue();
+            dest_node = (VRMLNodeType) nodeMap.get(src_node);
 
             scene.addDEFNode(name, dest_node);
         }
@@ -379,21 +379,27 @@ public abstract class CRProtoCreator
         Map<String, VRMLNode> def_map = scene.getDEFNodes();
         Map<String, Map<String, VRMLNode>> export_map = new HashMap<>();
 
+        Map.Entry<String, VRMLNode> e;
+        ImportNodeProxy value;
+        String key, inline;
+        ImportNodeProxy proxy;
+        Map<String, VRMLNode> exports;
+        VRMLInlineNodeType i_node;
         while(itr.hasNext()) {
-            Map.Entry<String, VRMLNode> e = itr.next();
+            e = itr.next();
             try {
-                ImportNodeProxy value = (ImportNodeProxy)e.getValue();
-                String key = e.getKey();
+                value = (ImportNodeProxy)e.getValue();
+                key = e.getKey();
 
-                ImportNodeProxy proxy = (ImportNodeProxy)value.clone();
+                proxy = (ImportNodeProxy)value.clone();
 
-                String inline = value.getInlineDEFName();
-                Map<String, VRMLNode> exports = export_map.get(inline);
+                inline = value.getInlineDEFName();
+                exports = export_map.get(inline);
                 if(exports == null) {
                     exports = new HashMap<>();
                     export_map.put(inline, exports);
 
-                    VRMLInlineNodeType i_node = (VRMLInlineNodeType)def_map.get(inline);
+                    i_node = (VRMLInlineNodeType)def_map.get(inline);
                     i_node.setImportNodes(exports);
                 }
 
diff --git a/src/java/org/web3d/vrml/renderer/ogl/OGLExternPrototypeDecl.java b/src/java/org/web3d/vrml/renderer/ogl/OGLExternPrototypeDecl.java
index 19b72302..5c325aa8 100644
--- a/src/java/org/web3d/vrml/renderer/ogl/OGLExternPrototypeDecl.java
+++ b/src/java/org/web3d/vrml/renderer/ogl/OGLExternPrototypeDecl.java
@@ -97,8 +97,7 @@ public class OGLExternPrototypeDecl extends CRExternPrototypeDecl {
                 "No matching PROTO instances in " + scene.getLoadedURI() +
                 " to match this EXTERNPROTO " + getVRMLNodeName());
 
-        VRMLWorldRootNodeType root =
-            (VRMLWorldRootNodeType)scene.getRootNode();
+        VRMLWorldRootNodeType root = (VRMLWorldRootNodeType)scene.getRootNode();
 
         setProtoDetails(proto_def);
         OGLProtoCreator creator =
diff --git a/src/java/org/xj3d/core/loading/ContentLoader.java b/src/java/org/xj3d/core/loading/ContentLoader.java
index 0f1c9934..54a8136e 100644
--- a/src/java/org/xj3d/core/loading/ContentLoader.java
+++ b/src/java/org/xj3d/core/loading/ContentLoader.java
@@ -39,19 +39,19 @@ class ContentLoader implements Runnable
     /** Message for an unexpected exception message */
     private static final String UNEXPECTED_EXCEPTION_MSG =
         "[ContentLoader] unexpected Xj3D exception during model loading";
-    
-    private static final String Xj3D_ISSUE_LIST = 
+
+    private static final String XJ3D_ISSUE_LIST =
             "New Xj3D issue needed to improve the open source, please see\n" +
             "  https://gitlab.nps.edu/Savage/xj3d/issues";
- 
+
     /** The threading running this loader */
     private Thread thread;
 
     /** The list of data we are fetching from */
-    private ContentLoadQueue pendingContentLoadQueue;
+    private final ContentLoadQueue pendingContentLoadQueue;
 
     /** The map of nodes we are currently loading to their loader */
-    private Map<String[], LoadRequest> inProgressLoadRequestMap;
+    private final Map<String[], LoadRequest> inProgressLoadRequestMap;
 
     /** Flag indicating that the current load should be terminated */
     private boolean terminateCurrent;
@@ -117,19 +117,19 @@ class ContentLoader implements Runnable
 
                 // Register now that we are processing this object
                 inProgressLoadRequestMap.put(currentLoadRequest.url, currentLoadRequest);
-                
+
                 currentLoadRequest.loadRequestHandler.processLoadRequest(errorReporter,
                                                                          currentLoadRequest.url,
                                                                      currentLoadRequest.loadDetailsList);
                 // Register now that we finished processing this object
                 inProgressLoadRequestMap.remove(currentLoadRequest.url);
-            } 
-            catch (Exception e) 
+            }
+            catch (Exception e)
             {
                 // Any other exception
 //                System.out.println ("ContentLoader exception:"); // debug
                 errorReporter.errorReport  (UNEXPECTED_EXCEPTION_MSG, e);
-                errorReporter.messageReport(Xj3D_ISSUE_LIST);
+                errorReporter.messageReport(XJ3D_ISSUE_LIST);
 //                e.printStackTrace(System.out); // debug
                 inProgressLoadRequestMap.remove(currentLoadRequest.url);
                 continue;
diff --git a/src/java/org/xj3d/core/loading/LoaderThreadPool.java b/src/java/org/xj3d/core/loading/LoaderThreadPool.java
index 73a80b61..5ec826e7 100644
--- a/src/java/org/xj3d/core/loading/LoaderThreadPool.java
+++ b/src/java/org/xj3d/core/loading/LoaderThreadPool.java
@@ -86,9 +86,9 @@ public class LoaderThreadPool {
         // fetch the system property defining the values
         Integer prop = AccessController.doPrivileged((PrivilegedAction<Integer>) () -> {
             int num_processors = Runtime.getRuntime().availableProcessors();
-            
+
             DEFAULT_THREAD_COUNT = (num_processors == 1) ? 1 : (num_processors - 1);
-            
+
             // privileged code goes here, for example:
             return Integer.getInteger(THREAD_COUNT_PROP, DEFAULT_THREAD_COUNT);
         });
@@ -99,7 +99,7 @@ public class LoaderThreadPool {
 
         if (size != DEFAULT_THREAD_COUNT)
             System.out.println(THREAD_COUNT_PROP + " set to: " + size);
-        
+
         loaders = new ContentLoader[size];
 
         for(int i = size; --i >= 0;)
@@ -226,13 +226,13 @@ public class LoaderThreadPool {
      * Ensure all threads are running.
      */
     public void restartThreads() {
-        
+
         // TODO: Deprecated in JDK16. How to compensate?
     	if (threadGroup.isDestroyed()) {
             threadGroup = null;
             threadPool = new LoaderThreadPool();
     	}
-        int size = loaders.length;
+//        int size = loaders.length;
         for(ContentLoader loader : loaders) {
             if(!loader.isAlive())
                 loader = new ContentLoader(threadGroup, pending, inProgress);
-- 
GitLab