dev@javaserverfaces.java.net

com.sun.faces.application.ViewHandlerImpl performance issue

From: Hongjoon Jeon <evencare_at_gmail.com>
Date: Wed, 14 Jun 2006 19:05:03 +0900

Hi, I'm a newbie JSF Developer.
When I've been researching the source code of JSF Sun RI, it strikes a
question
to me about the performance enhancing issue in
com.sun.faces.application.ViewHandlerImpl source code.

================================================================================
private void writeAfterViewContent
(ExternalContext extContext, ServletResponse response) throws IOException {
Object content = extContext.getRequestMap().get(AFTER_VIEW_CONTENT);
assert(null != content);
if (content instanceof byte []) {
response.getWriter().write(new String((byte[]) content));
} else if (content instanceof char []) {
response.getWriter().write((char []) content);
} else {
assert(false);
}

response.flushBuffer();

// remove the AFTER_VIEW_CONTENT from the view root
extContext.getRequestMap().remove(AFTER_VIEW_CONTENT);
}
================================================================================

In fact, most of contents may be 'char[]', so checking a content with
'byte[]'
first is inefficient, I think.

The code snippit below,

================================================================================
if (content instanceof byte []) {
response.getWriter().write(new String((byte[]) content));
} else if (content instanceof char []) {
response.getWriter().write((char []) content);
} else {
assert(false);
}
================================================================================

can be replaced like below.

================================================================================
if (content instanceof char []) {
response.getWriter().write((char []) content);
} else if (content instanceof byte []) {
response.getWriter().write(new String((byte[]) content));
} else {
assert(false);
}
================================================================================

Thank you.