Lew said:
Joshua said:
(e-mail address removed) wrote:
String value="";
if(value.length() == 0) {
char data[]=new char[count];
for(int c=0;c<count;c++){
data[c]='0';
}
value=new String(data);
Why do you want to optimize this code? Have you profiled to make sure
that it is these lines specifically that are the bottleneck?
If speed really is an issue, then the only thing that jumps out at me
for optimizing is getting rid of the for loop:
java.util.Arrays.fill(data, '0');
Is that faster? Enough faster?
It may be faster, depending on the system. The only way to tell if it is
enough faster is for the OP to measure it.
Many systems have a very fast way of pushing a repeated bit pattern to
an area of memory. For example, on Sun SPARC systems, 64 byte chunks of
memory can be written from the floating point registers.
If the OP's system has some such facility, and Arrays.fill is
implemented on that system as a native method using an optimized memory
write method, then it may be significantly faster than than writing one
char at a time.