Style question (was Re: Test)

Per Bothner bothner@cygnus.com
Wed Sep 16 11:46:00 GMT 1998


> This is how I have been doing things for a couple years now, but I always
> wonder what kind of performance hit I am taking by not moving the
> "char c" declaration outside the loop and breaking the age old rule.

Huh?  Declararions have no run-time cost on any Java implementation
I know.  In your example there to only thing you might want to
move outside the loop is not the declaration, but the loop test:
	k<thestring.length()
You might want to move:
	int len = thestring.length();
outside the loop, and use k<len as the termiation test.

Now, it should not be difficult to have the compiler "know" that
thestring.length() is constant if the string is the same object,
in which case the compiler can do the optimization for you.
(However, at this point, it does not.)

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner






More information about the Java mailing list