You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by aw...@apache.org on 2007/08/18 01:32:11 UTC

svn commit: r567173 - /myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java

Author: awiner
Date: Fri Aug 17 16:32:10 2007
New Revision: 567173

URL: http://svn.apache.org/viewvc?view=rev&rev=567173
Log:
TRINIDAD-633: StyleNode objects could be much more lightweight
- Use emptyList() for any zero-element arrays or empty sets
- Use singletonList() for any one-element array or set

Modified:
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java?view=diff&rev=567173&r1=567172&r2=567173
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/style/xml/parse/StyleNode.java Fri Aug 17 16:32:10 2007
@@ -74,28 +74,40 @@
     _selector = selector;
     _resetProperties = resetProperties;
 
+
+    // Structure copying:
+    // We have quite a lot of StyleNodes floating around;  so making
+    // them lightweight is highly desirable.  Consequently, use
+    // the lightest weight lists possible:  emptyList() if null
+    // or an empty array, and singletonList() if it's a one-element array
+
     // Initialize _properties
     // ------------------------------
-    if (properties != null)
-      _properties = Collections.unmodifiableList(Arrays.asList(properties));
-    else
+    if (properties == null || (properties.length == 0))
       _properties = Collections.emptyList();
-
+    else if (properties.length == 1)
+      _properties = Collections.singletonList(properties[0]);
+    else
+      _properties = Collections.unmodifiableList(Arrays.asList(properties));
 
     // Initialize _includedStyles
     // ------------------------------
-    if (includedStyles != null)
-      _includedStyles = Collections.unmodifiableList(Arrays.asList(includedStyles));
-    else
+    if ((includedStyles == null) || (includedStyles.length == 0))
       _includedStyles = Collections.emptyList();
+    else if (includedStyles.length == 1)
+      _includedStyles = Collections.singletonList(includedStyles[0]);
+    else
+      _includedStyles = Collections.unmodifiableList(Arrays.asList(includedStyles));
 
 
     // Initialize _includedProperties
     // ------------------------------
-    if (includedProperties != null)
-      _includedProperties = Collections.unmodifiableList(Arrays.asList(includedProperties));
-    else
+    if ((includedProperties == null) || (includedProperties.length == 0))
       _includedProperties = Collections.emptyList();
+    else if (includedProperties.length == 1)
+      _includedProperties = Collections.singletonList(includedProperties[0]);
+    else
+      _includedProperties = Collections.unmodifiableList(Arrays.asList(includedProperties));
       
       
     // Initialize _inhibitAll and _inhibitedProperties
@@ -103,7 +115,7 @@
     boolean inhibitAll = false;
     // Convert inhibitedProperties Set to an unmodifiableList
 
-    if(inhibitedProperties != null)
+    if ((inhibitedProperties != null) && !inhibitedProperties.isEmpty())
     {
       List<String> inhibitedPropertiesList = new ArrayList<String>(inhibitedProperties.size());
       for(String property : inhibitedProperties)
@@ -135,7 +147,10 @@
         }
       }
 
-      _inhibitedProperties = Collections.unmodifiableList(inhibitedPropertiesList);
+      if (inhibitedPropertiesList.size() == 1)
+        _inhibitedProperties = Collections.singletonList(inhibitedPropertiesList.get(0));
+      else
+        _inhibitedProperties = Collections.unmodifiableList(inhibitedPropertiesList);
 
     }
     else