[Pki-devel] [PATCH] 0012 - Fixes for Coverity Issues of type StringBuffer_Concatenation, Wrong_Map_Iterator, No_Equals_Method , Reverse_INull for DogTag 10

Endi Sukma Dewata edewata at redhat.com
Fri Jun 15 02:02:03 UTC 2012


On 6/14/2012 7:36 PM, Ade Lee wrote:
>> Every time you do a "+" operation on Strings, the JVM will create a
>> StringBuilder, append the Strings, then generate a new String that
>> contains the concatenated text. So instead of this:
>>
>>     splitTimes.append(
>>         "," + Long.toString(deltaTime) + "," + Long.toString(crlTime)
>>         + "," + Long.toString(totalTime) + ")");
>>
>> you can reuse the same StringBuilder object like this:
>>
>>     splitTimes.append(",").append(deltaTime).append(",").append(crlTime)
>>         .append(",").append(totalTime).append(")");
>>
>
> While I appreciate that the above formulation is more efficient, there
> is a drawback in terms of readability.  This following formulation may
> be a little less efficient but is much more readable:
>
> splitTimes.append("," + deltaTime + "," + crlTime + "," + totalTime + ")");
>
> I suggest that we not sacrifice readability for efficiency until we have
> profiling data in hand. I suspect that this little inefficiency will be
> the very least of our performance issues.

Agreed. For better readability we can use this:

   splitTimes.append(
       String.format(",%d,%d,%d)", deltaTime, crlTime, totalTime));

-- 
Endi S. Dewata




More information about the Pki-devel mailing list