You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Paul Benedict (JIRA)" <ji...@apache.org> on 2009/11/26 06:17:39 UTC

[jira] Commented: (LANG-508) Validate: add message parameter construction via elllipsis notation to speed up processing

    [ https://issues.apache.org/jira/browse/LANG-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12782748#action_12782748 ] 

Paul Benedict commented on LANG-508:
------------------------------------

If we want to implement LANG-508 (Validate: add message parameter construction via elllipsis notation to speed up processing), I am really concerned with the many overloaded versions of #validIndex() and #notEmpty() that solely differ by static argument type: Collection, Object, Object[], CharSequence, etc.

Because var-args instantiate a new Object[], it won't be possible to easily create one-argument optimized overloaded versions to prevent the creation. Such as:
public static <T> T[] notEmpty(Object array, String message, Object var1);
public static <T> T[] notEmpty(Object array, String message, Object var1, Object var2);
public static <T> T[] notEmpty(Object array, String message, Object var1, Object var2, Object var3);
public static <T> T[] notEmpty(Object array, String message, Object var1, Object var2, Object var3, Object... vars);

I am following the good advice on Joshua Bloch on this one. It's item #42 in his Effective Java book.

I want to eliminate the overloaded versions by type and check those types using instanceof instead. Thoughts?

> Validate: add message parameter construction via elllipsis notation to speed up processing
> ------------------------------------------------------------------------------------------
>
>                 Key: LANG-508
>                 URL: https://issues.apache.org/jira/browse/LANG-508
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.4
>            Reporter: Mark Struberg
>             Fix For: 3.0
>
>         Attachments: LANG-508.patch
>
>
> Currently passing verbose message strings to a log of commons.lang.Validate functions costs a lot of performance.
> A typical usecase currently is:
> {noformat}
> Validate.isTrue (argInt1.intValue > argInt2.intValue, "param2 actually is " + argInt2 + " but must larger than param1 " + argInt1 +" !");
> {noformat}
> So all the string operations get executed regardless if the validation fails or not.
> This can be made perform much better by moving all the string operations inside the respective validation function and execute it only if the validation fails:
> {noformat}
> Validate.isTrue(argInt1.intValue > argInt2.intValue, "param2 actually is {1} but must larger than param1 {0} !", argInt1, argInt2);
> {noformat}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.