On Tue, May 26, 2009 at 12:47 AM, Robert Green <rbgrn....@gmail.com> wrote:

>
> That is SO MUCH more code than I ever wanted there but it's
> ridiculously more efficient than it was before so I'm going to call it
> good and move on.
>

It looks like a lot of your code comes from C code that had to run very very
fast
on very old CPUs that didn't have fast multiplication instructions.
Unfortunately,
they risk to be slower than necessary on Dalvik. May I suggest the much
simpler
alternative:

public static void getChars(int i, int index, char[] buf)
{
    if (i == Integer.MIN_VALUE) {
        System.arraycopy("-2147483648".toCharArray(), 0, buf, 0,
buf.length);
    }
    int q, r;
    // assumes 'index' accounts for the sign if present
    int charPos = index;
    char sign = 0;

    if (i < 0) {
            sign = '-';
            i = -i;
            index -= 1;
    }

    while (index > 0) {
        q = i / 10;
        r = i - q*10;
        buf[--charPos] = '0' + r;
        i = q;
        index--;
    }

    if (sign != 0) {
            buf[--charPos] = sign;
    }
}



>
> Thanks for the help everyone!
>
> On May 25, 5:19 pm, Jason Proctor <ja...@particularplace.com> wrote:
> > i'll suggest this again :-)
> >
> > when the score changes, convert to a string then, save it away, and
> > draw that each frame. at least then, you're only doing an allocation
> > when it changes.
> >
> > good enough?
> >
> >
> >
> > >My new method doesn't have problems with concatenating but no solution
> > >so far has gotten around converting an integer into a String or
> > >CharSequence.  Any time you put an integer where a String should be,
> > >java automatically uses Integer.toString(i) to build a String out of
> > >it which allocates a char[] and also makes a new String.
> >
> > >So, besides ripping out stringSize and getChars from integer and
> > >holding my own char[] for the converted int, is there a clean way to
> > >handle that without new allocations?
> >
> > >On May 25, 4:29 pm, Jason Proctor <ja...@particularplace.com> wrote:
> > >>  i think Mark is saying that you could redraw the score separately
> > >>  from the label, potentially saving an implicit new StringBuffer
> > >>  (stuff).toString () ?
> >
> > >>  if score is a number, then it will need to make a new String anyway.
> > >>  but you could cache the string of the score until the score changes,
> > >>  so that drawing the score becomes drawing to strings as opposed to
> > >>  going through StringBuffer.
> >
> > >>  hth
> >
> > >>  >It's a surface view so the whole scene must be rendered every frame.
> > >>  >I could put it on the background I suppose but it's simple enough to
> > >>  >just redraw the text.
> >
> > >>  >On May 25, 4:10 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> > >>  >>  Robert Green wrote:
> > >>  >>  > I said StringBuffer but I meant "Implied" StringBuffer, you
> know:
> >
> > >>  >>  > canvas.drawText(score + POINTS_LABEL, x, y, paint);
> >
> > >>  >>  Why redraw POINTS_LABEL every time? Can't you rework your
> scoreboard to
> > >>  >>  only draw that once?
> >
> > >>  >>  --
> > >>  >>  Mark Murphy (a Commons
> > >>  >>Guy)http://commonsware.com|http://twitter.com/commonsguy
> >
> > >>  >>  Android App Developer Training:
> http://commonsware.com/training.html
> >
> > >>  --
> > >>  jason.software.particle
> >
> > --
> > jason.software.particle
> >
>

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