[ 
https://issues.apache.org/jira/browse/LOG4J2-1271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15152109#comment-15152109
 ] 

Remko Popma edited comment on LOG4J2-1271 at 2/18/16 10:37 AM:
---------------------------------------------------------------

Something like this:
{code}
// ParameterizedMessage or other allocation-free message implementation
private void append(Object param, StringBuilder buffer) {
    if (param instanceof StringBuilder) {
        buffer.append((StringBuilder) param);
    } else if (param instanceof LogMessageParameter) {
        ((LogMessageParameter) param).writeTo(buffer);
    } else {
        buffer.append(param); // calls param.toString()
    }
}
{code}


was (Author: rem...@yahoo.com):
Something like this:
{code}
private void append(Object param, StringBuilder buffer) {
    if (param instanceof StringBuilder) {
        buffer.append((StringBuilder) param);
    } else if (param instanceof LogMessageParameter) {
        ((LogMessageParameter) param).writeTo(buffer);
    } else {
        buffer.append(param); // calls param.toString()
    }
}
{code}

> ParameterizedMessage optimization
> ---------------------------------
>
>                 Key: LOG4J2-1271
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1271
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: 2.5
>            Reporter: Remko Popma
>            Assignee: Remko Popma
>
> ParameterizedMessage creates unnecessary objects and does other unnecessary 
> work in its constructor.
> On the other hand, it does not create the full formatted string it will 
> eventually need to return from {{getFormattedMessage()}}.
> I propose the following changes:
> * Don't call {{argumentsToStrings}} in the constructor. Converting the 
> parameter Object[] array to a String[] array should only be done when 
> necessary: when this ParameterizedMessage is serialized.
> * Don't copy the parameter Object[] array to a new array. Instead clone the 
> array when the {{getParameters()}} method is called.
> * In the constructor, build the fully formatted message. This combines the 
> work done by {{formatStringArgs(String, String[])}} and 
> {{argumentsToStrings(Object[])}} and avoids the issue mentioned in LOG4J2-763.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to