-
Bug
-
Resolution: Fixed
-
P4
-
1.1, 1.1.3
-
1.1.6
-
generic, x86, sparc
-
generic, solaris_2.5, windows_95
-
Not verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2017659 | 1.2.0 | Richard Gillam | P4 | Resolved | Fixed | 1.2beta3 |
In java.util.ResourceBundle there is the exact example of a style that
at JavaOne this year I told people to avoid. Sigh. There's the method
/**
* For printf debugging.
*/
private static boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("ResourceBundle: " + str);
}
}
and then sprinkled throughout the code are calls of the form
debug("Searching for parent " + baseName + localeName);
debug("Found " + searchName + " in cache as NOTFOUND");
debug("Found " + searchName + " in cache");
debug("Searching for " + searchName );
debug("Searching for " + searchName );
debug("Adding " + cacheCandidates.elementAt(i) + " to cache"
debug("Adding " + cacheCandidates.elementAt(i)
The problem with this style is that the argument String gets constructed,
even though when it arrives in the debug method it gets dropped on the
floor. That's StringBuffer allocations, char[] allocations, synchronized
StringBuffer.append() calls, arraycopy's for the chars, and if the argument
gets longer than the default StringBuffer (16 chars), reallocating the
char[] inside the StringBuffer and arraycopy'ing the chars again, then
allocating and constructing a String from the StringBuffer. All dropped on
the floor.
The solution is to hoist the if test out of the debug method and inline
it at all the call sites. It's not as pretty as macros in C, but it
doesn't generate any code and doesn't waste any time or space.
peter.kessler@Eng 1997-10-30
at JavaOne this year I told people to avoid. Sigh. There's the method
/**
* For printf debugging.
*/
private static boolean debugFlag = false;
private static void debug(String str) {
if( debugFlag ) {
System.out.println("ResourceBundle: " + str);
}
}
and then sprinkled throughout the code are calls of the form
debug("Searching for parent " + baseName + localeName);
debug("Found " + searchName + " in cache as NOTFOUND");
debug("Found " + searchName + " in cache");
debug("Searching for " + searchName );
debug("Searching for " + searchName );
debug("Adding " + cacheCandidates.elementAt(i) + " to cache"
debug("Adding " + cacheCandidates.elementAt(i)
The problem with this style is that the argument String gets constructed,
even though when it arrives in the debug method it gets dropped on the
floor. That's StringBuffer allocations, char[] allocations, synchronized
StringBuffer.append() calls, arraycopy's for the chars, and if the argument
gets longer than the default StringBuffer (16 chars), reallocating the
char[] inside the StringBuffer and arraycopy'ing the chars again, then
allocating and constructing a String from the StringBuffer. All dropped on
the floor.
The solution is to hoist the if test out of the debug method and inline
it at all the call sites. It's not as pretty as macros in C, but it
doesn't generate any code and doesn't waste any time or space.
peter.kessler@Eng 1997-10-30
- backported by
-
JDK-2017659 ResourceBundle.debug wastes time and space
- Resolved
- duplicates
-
JDK-4088100 wasteful code in ResourceBundle.java
- Closed