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/07/17 00:27:12 UTC
svn commit: r556755 -
/myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java
Author: awiner
Date: Mon Jul 16 15:27:04 2007
New Revision: 556755
URL: http://svn.apache.org/viewvc?view=rev&rev=556755
Log:
TRINIDAD-106: CoreRenderer.renderStyleClasses() API non-obviously mutates the array
- Redo renderStyleClasses() implementation so that it doesn't need to mutate the array
Modified:
myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java
Modified: myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java?view=diff&rev=556755&r1=556754&r2=556755
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java Mon Jul 16 15:27:04 2007
@@ -612,42 +612,60 @@
/**
* Render an array of CSS styleClasses as space-separated values.
- * NOTE: the array is mutated during this method, and cannot
- * be reused! Each styleclass will be passed through the RenderingContext
- * getStyleClass() API.
* @param context the FacesContext
* @param styleClasses the style classes
*/
static public void renderStyleClasses(
FacesContext context,
- RenderingContext arc,
+ RenderingContext rc,
String[] styleClasses) throws IOException
{
- int length = 0;
- for (int i = 0; i < styleClasses.length; i++)
+ int length = styleClasses.length;
+ if (length == 0)
+ return;
+
+ String value;
+ // Optimize one-element arrays
+ if (length == 1)
{
- if (styleClasses[i] != null)
- {
- String styleClass = arc.getStyleClass(styleClasses[i]);
- if (styleClass != null)
- length += styleClass.length() + 1;
- styleClasses[i] = styleClass;
- }
+ value = rc.getStyleClass(styleClasses[0]);
}
-
- StringBuilder builder = new StringBuilder(length);
- for (int i = 0; i < styleClasses.length; i++)
+ // Otherwise, build up the array of mutated style classes.
+ else
{
- if (styleClasses[i] != null)
+ // Assume that styleclass compression is active in terms of sizing
+ // this buffer - this is not true for portlets, but this isn't a
+ // huge optimizations, and the relatively smaller content delivered
+ // to portlets makes this still less important
+ StringBuilder builder =
+ new StringBuilder((_COMPRESSED_LENGTH + 1) * length);
+ for (int i = 0; i < length; i++)
{
- if (builder.length() != 0)
- builder.append(' ');
- builder.append(styleClasses[i]);
+ if (styleClasses[i] != null)
+ {
+ String styleClass = rc.getStyleClass(styleClasses[i]);
+ if (styleClass != null)
+ {
+ if (builder.length() != 0)
+ builder.append(' ');
+ builder.append(styleClass);
+ }
+ }
}
+
+ if (builder.length() == 0)
+ value = null;
+ else
+ value = builder.toString();
}
- context.getResponseWriter().writeAttribute("class", builder.toString(), null);
+ context.getResponseWriter().writeAttribute("class", value, null);
}
+
+
+ // Heuristic guess of the maximum length of a typical compressed style
+ private static final int _COMPRESSED_LENGTH = 4;
+
private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
CoreRenderer.class);
}