Path: csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!aioe.org!.POSTED!not-for-mail From: Roedy Green Newsgroups: comp.lang.java.programmer Subject: Re: replace extended characters Date: Fri, 11 Feb 2011 17:05:23 -0800 Organization: Canadian Mind Products Lines: 31 Message-ID: References: <15bd3363-c781-487b-98d5-2243eff7cc8f@24g2000yqa.googlegroups.com> <0bgbl698d19hku2vlldf5rldbsebis933u@4ax.com> Reply-To: Roedy Green NNTP-Posting-Host: RCd/Ul4tyxGUBII8WGwa5g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Forte Agent 6.00/32.1186 Xref: csiph.com comp.lang.java.programmer:25591 On Fri, 11 Feb 2011 18:40:50 -0500, Joshua Cranmer wrote, quoted or indirectly quoted someone who said : >The Java compiler will make switch statements into a straight jump table >if it's dense enough, but jump tables can wreak havoc on caches and >branch predicting, so the JIT may unroll jump tables into better >constructs at runtime. There are two constructs in byte code to support switch: tableswitch for dense keys which does a jump table and lookupswitch for sparsekeys which could be implemented with binary search, or linear search or any of an number of other clever means the JVM could concoct. I decompiled a number of switches a while back, and was disappointed to see it nearly always use lookupswitch, even where I would have used tableswitch. This suggests, if you want to guarantee the efficient version, design your keys to be dense ints starting at 0. You can often replace a switch with an array or Map data lookup, or array lookup of a delegate. Switch is a queer bit of syntax, with its default fallthru. There is nothing else like it in Java. -- Roedy Green Canadian Mind Products http://mindprod.com Refactor early. If you procrastinate, you will have even more code to adjust based on the faulty design. .