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
-~----------~----~----~----~------~----~------~--~---

Reply via email to