I have the following java method, written for an android application.
private String removeWifiFudge(String message, String removedFudge)
{
int find1 = 255; //FF
int find2 = 0; //00
int find3 = 204; //CC
int find4 = 36; //24
char[] charMessage = message.toCharArray();
boolean find1True = false;
for (char eachCharacter : charMessage)
{
if (find1True)
{
if ((int) eachCharacter == find2)
{
removedFudge = removedFudge + String.valueOf((char)find1);
}
else
{
if ((int) eachCharacter == find3)
{
removedFudge = removedFudge + String.valueOf((char)find4);
}
else
{
removedFudge = removedFudge + String.valueOf((char)find1);
removedFudge = removedFudge + String.valueOf(eachCharacter);
}
}
find1True = false;
}
else
{
if ((int) eachCharacter == find1)
{
find1True = true;
}
else
{
removedFudge = removedFudge + String.valueOf(eachCharacter);
}
}
}
return removedFudge;
}
In a nutshell, it takes a string, message and searches it character by character for instances of 0xFF00 and 0xFFCC. On finding these instances, it replaces them by 0xFF and 0x24 respectively, putting it in a new string removedFudge.
This method is taking up a massive percentage of the CPU time and whilst using the java profiler embedded in eclipse, DDMS, it informed me 53% of the method time is spent:
java/lang/StringBuilder. (Ljava/lang/String;)V
This seems to be saying it is taking up the time initialising a string, however as I am passing it the already initialised string to put the new message in, I can't see where the initialising String is coming from.
Anyone an expert on DDMS?