On Tue, Jun 2, 2009 at 11:27 PM, Robert Green <[email protected]> wrote:
> > David, > > That's not my code - that was a package method ripped from > java.lang.Integer. I had to copy/post it because it's needed to make > write an int's String's char[] directly without instantiating > anything. > no problem :-) I was just seeing you complaining about "that much more code" so I thought I could help reduce the burden. After all, if something's not broken... > > On Jun 2, 7:27 am, David Turner <[email protected]> wrote: > > On Tue, May 26, 2009 at 12:47 AM, Robert Green <[email protected]> > 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 <[email protected]> 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 <[email protected]> > 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 <[email protected]> > 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

