[java]
public String padNumZero(float num, int wholeLen, int decimalPlaces) {
// …
dpLoc = numStr.indexOf(".");
int length = numStr.substring(dpLoc).length();
while (length < decimalPlaces) {//< ---------------------------------- FIXME: this definitely will never end ;)
numStr += "0";
}
return numStr;
}
[/java]
Suggested fix:
[java]
public String padNumZero(float num, int wholeLen, int decimalPlaces) {
// …
My guess is that there is actually a missing length++. The anti-idiom here is using a while() loop instead of a for() loop when the latter is closer to intent.
…but anyway, I also wonder if it’s even used and can just be removed.
Actually modern compilers turn string concatenation into StringBuilder behind the scenes. I’m not sure just how smart they are about it but I think in that case they would catch it.
Yes, that’s how String concatenation is defined.
The OpenJDK compiler isn’t smart enough to hoist the StringBuilder outside the loop though, so the string data is still copied every time through the loop.
The method is never used indeed, only a subset of the class’ methods is used in the jme3tools.navigation package.
I think it’s a very old contribution about navigation (as in sailing). I don’t really know why it’s in the core, it would fit as a plugin IMO. But maybe at the time making it a plugin wasn’t an option.
Maybe @normen knows something about it.
IMO the whole package should be removed from core.
@nehon said:
The method is never used indeed, only a subset of the class' methods is used in the jme3tools.navigation package.
I think it's a very old contribution about navigation (as in sailing). I don't really know why it's in the core, it would fit as a plugin IMO. But maybe at the time making it a plugin wasn't an option.
Maybe @normen knows something about it.
IMO the whole package should be removed from core.