I have already try to use array of classes for every branch of switch, but it seems to be tooo slooow, because of Android architecture or of other reasons.
My switch looks like: switch(opcode) { case 0x00: ... break; case 0x01: ... break; case 0x02: ... break; ....................... case 0xFF: ... break; } Thanks to all! I'll try to use 255 classes again.... may be there were some mistakes in my generated code... Thanks again! On 27 мар, 02:19, Dan Bornstein <danf...@android.com> wrote: > On Thu, Mar 26, 2009 at 3:06 PM, HotHeart <korshakov.ste...@gmail.com> > wrote: > > > I have switch with 255 cases in my project - DroidGear... > > How i could optimize it? > > Other people have already covered much of the territory, but I wanted > to add that it is more efficient to execute a switch code where all > the case keys are packed together, with no gaps (or only a few small > gaps), since the underlying runtime can do a simple calculated lookup > in that case rather than searching through a table of keys. E.g.: > > // efficient > switch (x) { case 2: ...; case 3: ...; case 4: ...; case 5: ... } > > // inefficient > switch (x) { case 100: ...; case 200: ...; case 300: ...; case > 400: ... } > > That said, unless it is being used in the inner loop of a time- > consuming CPU-bound function, you probably won't notice the > difference. > > -dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---