Re: svn commit: r1482067 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r1482067 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java

Adrian Crum-3
Ummm...

I have a List in my hand. Instead of calling the size() method on that
List, I hand it over to a method in another class that calls the size()
method. How is that an optimization?

-Adrian

On 5/13/2013 9:06 PM, [hidden email] wrote:

> Author: doogie
> Date: Mon May 13 20:06:03 2013
> New Revision: 1482067
>
> URL: http://svn.apache.org/r1482067
> Log:
> OPTIMIZE: join() now calls UtilValidate.isEmpty().
>
> Modified:
>      ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
>
> Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java?rev=1482067&r1=1482066&r2=1482067&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java (original)
> +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java Mon May 13 20:06:03 2013
> @@ -165,7 +165,7 @@ public class StringUtil {
>        * @return a String of all values in the list seperated by the delimiter
>        */
>       public static String join(List<?> list, String delim) {
> -        if (list == null || list.size() < 1)
> +        if (UtilValidate.isEmpty(list))
>               return null;
>           StringBuilder buf = new StringBuilder();
>           Iterator<?> i = list.iterator();
>
>

Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r1482067 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java

Adam Heath-2
Then remove all calls to UtilValidate in other parts of the code. :|

On 05/14/2013 12:09 PM, Adrian Crum wrote:

> Ummm...
>
> I have a List in my hand. Instead of calling the size() method on that
> List, I hand it over to a method in another class that calls the
> size() method. How is that an optimization?
>
> -Adrian
>
> On 5/13/2013 9:06 PM, [hidden email] wrote:
>> Author: doogie
>> Date: Mon May 13 20:06:03 2013
>> New Revision: 1482067
>>
>> URL: http://svn.apache.org/r1482067
>> Log:
>> OPTIMIZE: join() now calls UtilValidate.isEmpty().
>>
>> Modified:
>>      ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
>>
>> Modified:
>> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
>> URL:
>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java?rev=1482067&r1=1482066&r2=1482067&view=diff
>>
>> ==============================================================================
>>
>> ---
>> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
>> (original)
>> +++
>> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
>> Mon May 13 20:06:03 2013
>> @@ -165,7 +165,7 @@ public class StringUtil {
>>        * @return a String of all values in the list seperated by the
>> delimiter
>>        */
>>       public static String join(List<?> list, String delim) {
>> -        if (list == null || list.size() < 1)
>> +        if (UtilValidate.isEmpty(list))
>>               return null;
>>           StringBuilder buf = new StringBuilder();
>>           Iterator<?> i = list.iterator();
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r1482067 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java

Adam Heath-2
In reply to this post by Adrian Crum-3
Well, size() itself can be heavyweight, consider a LinkedList, or one
of the concurrent classes.  isEmpty() calls Collection.empty().

Also, with more things calling the lower-level support methods, the
JIT can see that the called code is a hot-path, and decide to inline.
 With copies of the code all over, that can't happen.

On 05/14/2013 12:09 PM, Adrian Crum wrote:

> Ummm...
>
> I have a List in my hand. Instead of calling the size() method on that
> List, I hand it over to a method in another class that calls the
> size() method. How is that an optimization?
>
> -Adrian
>
> On 5/13/2013 9:06 PM, [hidden email] wrote:
>> Author: doogie
>> Date: Mon May 13 20:06:03 2013
>> New Revision: 1482067
>>
>> URL: http://svn.apache.org/r1482067
>> Log:
>> OPTIMIZE: join() now calls UtilValidate.isEmpty().
>>
>> Modified:
>>      ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
>>
>> Modified:
>> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
>> URL:
>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java?rev=1482067&r1=1482066&r2=1482067&view=diff
>>
>> ==============================================================================
>>
>> ---
>> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
>> (original)
>> +++
>> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
>> Mon May 13 20:06:03 2013
>> @@ -165,7 +165,7 @@ public class StringUtil {
>>        * @return a String of all values in the list seperated by the
>> delimiter
>>        */
>>       public static String join(List<?> list, String delim) {
>> -        if (list == null || list.size() < 1)
>> +        if (UtilValidate.isEmpty(list))
>>               return null;
>>           StringBuilder buf = new StringBuilder();
>>           Iterator<?> i = list.iterator();
>>
>>
>