Re: Fastest way to push strings to the screen in an NSView?
Re: Fastest way to push strings to the screen in an NSView?
- Subject: Re: Fastest way to push strings to the screen in an NSView?
- From: Guy English <email@hidden>
- Date: Fri, 19 Nov 2004 10:49:18 -0500
Hey,
Actually - he only allocates his text storage and layout manager
once per frame with his new method (assuming drawNumbersRect is called
only once per frame). The old method would have done something
simillar for each string he drew. So, in theory at least, this should
be faster. He was probably hitting a fast-path with his old code - he
appears to be drawing in black in a flipped view and has only numeric
glyphs so maybe they all fit in somekind of cache easilly. He also
calls -size on his text storage which probably needs to do a fair
amount of work since the string is changing beneath it all the time.
My suggestion would be to put the numbers into their own class or
C struct. I imagine they don't move around or change their values too
much. Create a new HexNumber instance that holds the
NSAttributedString, transform matrix (which should include the
adjustment to center the string) and draw rect (probably
(0,0,string.width,string.height). Then just loop through the visible
ones and blit 'em the easy way with -drawInRect. Also - don't invert
the transform then concat it back - instead just push and pop the
matrix stack. So thats saveGraphicsState and restoreGraphicsState.
That's much more likely to be optimized than a matrix invert plus you
don't have to understand math! :)
Hope that helps a little,
Guy
On Fri, 19 Nov 2004 06:46:43 -0700, Robbie Haertel
<email@hidden> wrote:
> I'm assuming your - (void) drawNumbersRect:(HexRedraw*) redraw method
> gets called for every drawRect. The biggest problem you have is you
> create and allocate a new layout manager, textStorage, and text
> container every time (if indeed this method is called frequently).
> This is similar to what NS[Attributed]String's drawInRect does, which
> is why it is slow. It is still interesting that it is slower, but to
> get the speed up, make them instance variables. There may be other
> inefficiencies, too, but if this method is called frequently, that is
> the biggest one!.
>
> Robbie
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden