|
From: | Eric Blake |
Subject: | Re: Patch: FYI: gnu.java.io.PlatformHelper |
Date: | Wed, 21 Jan 2004 07:05:57 -0700 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 |
Michael Koch wrote:
On Wed, Jan 21, 2004 at 11:20:24AM +0100, Jeroen Frijters wrote:+ int len = path.length(); + return len > 0 && beginWithRootPathPrefix(path) == len;just a thought but wouldnt it be cleaner to write this: return (path.length() > 0 && beginWithRootPathPrefix(path) == path.length(); Compilers are/should be smart enough to optimize it to write path.length into a register and use it twice.
Actually, jikes does not do CSE when emitting bytecode; it assumes that any common subexpression elimination will be done by a JIT. Therefore, Jeroen's style produces a smaller .class file than Michael's. Besides, path.length() is a function call, and it becomes very hard for the compiler to guarantee that it will return the same value twice; manually caching the result generally results in fewer method invocations.
-- Someday, I might put a cute statement here. Eric Blake address@hidden
[Prev in Thread] | Current Thread | [Next in Thread] |