harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r1006115 - /harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/LogManager.java
Date Sat, 09 Oct 2010 08:24:20 GMT
Author: regisxu
Date: Sat Oct  9 08:24:19 2010
New Revision: 1006115

URL: http://svn.apache.org/viewvc?rev=1006115&view=rev
Log:
Performance improvement for LogManager.addToFamilyTree

If parent is not root, do not need to travel all loggers.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/LogManager.java

Modified: harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/LogManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/LogManager.java?rev=1006115&r1=1006114&r2=1006115&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/LogManager.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/LogManager.java
Sat Oct  9 08:24:19 2010
@@ -32,6 +32,8 @@ import java.util.Collection;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Properties;
 import java.util.Set;
 import java.util.StringTokenizer;
@@ -321,26 +323,46 @@ public class LogManager {
         }
 
         // find children
-        // TODO: performance can be improved here?
-        Collection<Logger> allLoggers = loggers.values();
-        boolean emptyName = name.length() == 0;
-        String namePrefix = name + '.';
-        for (final Logger child : allLoggers) {
-            Logger oldParent = child.getParent();
-            if (parent == oldParent
-                    && (emptyName || child.getName().startsWith(namePrefix))) {
-                final Logger thisLogger = logger;
-                AccessController.doPrivileged(new PrivilegedAction<Object>() {
+        final boolean isNameEmpty = (name.length() == 0);
+        final Logger thisLogger = logger;
+        final String namePrefix = isNameEmpty ? "" : name + '.';
+        /*
+         * find only children under the current parent (others can
+         * not be children of the new logger)
+         */
+        if (parent == null) {
+            // parent is root, need to check all loggers to find children.
+            final Collection<Logger> allLoggers = loggers.values();
+            AccessController
+                    .doPrivileged(new PrivilegedAction<Object>() {
+                        public Object run() {
+                            for (final Logger child : allLoggers) {
+                                if (null == child.getParent()
+                                        && (child.getName().startsWith(namePrefix)))
{
+                                    child.setParent(thisLogger);
+                                }
+                            }
+                            return null;
+                        }
+            });
+        } else {
+            final List<Logger> childs = parent.children;
+            final Logger oldParent = parent;
+            AccessController.doPrivileged(new PrivilegedAction<Object>() {
                     public Object run() {
-                        child.setParent(thisLogger);
+                        final List toBeRemoved = new LinkedList();
+                        for (final Logger element : childs) {
+                            final String elementName = element.getName();
+                            if (elementName != null && elementName.startsWith(namePrefix))
{
+                                element.setParent(thisLogger);
+                                toBeRemoved.add(element);
+                            }
+                        }
+                        // remove child as the parent has been changed
+                        oldParent.children.removeAll(toBeRemoved);
                         return null;
                     }
                 });
-                if (null != oldParent) {
-                    // -- remove from old parent as the parent has been changed
-                    oldParent.children.remove(child);
-                }
-            }
         }
     }
 



Mime
View raw message