You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2013/05/13 22:06:04 UTC
svn commit: r1482067 -
/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
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();
Re: svn commit: r1482067 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
Posted by Adam Heath <do...@brainfood.com>.
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, doogie@apache.org 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();
>>
>>
>
Re: svn commit: r1482067 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
Posted by Adam Heath <do...@brainfood.com>.
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, doogie@apache.org 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();
>>
>>
>
Re: svn commit: r1482067 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
Posted by Adrian Crum <ad...@sandglass-software.com>.
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, doogie@apache.org 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();
>
>