Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Apple’s SimpleTextInput sample code is inefficient

I’m looking at Apple’s SimpleTextInput sample code, which is a sample project for an iOS text editor that uses Core Text to display the text. This is a wonderful thing.

But its ReadMe document says:

This sample code should not be considered a template for a text editor, but rather as an example of how to bind the text input system to a pre-existing text editor. The project's use of CoreText is naive and inefficient; it deals only with left-to-right text layout, and it is by no means a good template for any text editor. It is a implementation meant only to illustrate how to bind the system keyboard (that is, the text input system) to some pre-existing text editor.

I’m curious as to how this text editor is inefficient. Is it something fundamental in its design? Is it something that simple tweaks could improve? UITextView might have really elaborate caching algorithms hidden in it; so, would the problem be that SimpleTextInput lacks them?

like image 581
jschoi Avatar asked Oct 30 '11 16:10

jschoi


1 Answers

Apple’s SimpleTextInput sample code, uses Draw text all at once in single CTFrameRef object: This is the simplest options as you can get core text to just draw everything in one block. The only downside of this is that it can be inefficient as recreating CTFrameRef on every keystroke and redrawing all the text every time it is edited will slow your app down especially if there is a lot of text plus a lot of attributes.

For more efficient ways of implementing Core text editor read Rich Text Editing : The choices topic:Draw line by line.

like image 80
atrane Avatar answered Dec 06 '22 12:12

atrane