Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25591
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: replace extended characters |
| Date | 2011-02-11 17:05 -0800 |
| Organization | Canadian Mind Products |
| Message-ID | <hqmbl6hj8mvtsevmhu8dca97tcutdcrihb@4ax.com> (permalink) |
| References | <15bd3363-c781-487b-98d5-2243eff7cc8f@24g2000yqa.googlegroups.com> <i4gbl6houh7bon6rvfjii3rdel829ql2hi@4ax.com> <0bgbl698d19hku2vlldf5rldbsebis933u@4ax.com> <ij4he5$dgu$1@news.eternal-september.org> |
On Fri, 11 Feb 2011 18:40:50 -0500, Joshua Cranmer <Pidgeot18@verizon.invalid> 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. .
Back to comp.lang.java.programmer | Previous | Next | Find similar
Re: replace extended characters Roedy Green <see_website@mindprod.com.invalid> - 2011-02-11 17:05 -0800
csiph-web