December 12, 2006

truncateToFit() performance problem

Setting very long string to the text property of classes that decorate UITextField (e. g. Label) causes timeout exception. Take a look at the truncateToFit() method in UITextField class. You could find this block there:

It means that actual text is cut char by char until result of its concatenation with truncation indicator fits into the width available or only one char left. When text is very long this looping is almost infinitive. I believe it would work much more faster with division by 2 approach. In this case even 64K text truncation will take only 16 loop cycles.

No comments: