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.