3

我发现在 iOS5 中使用 CTFramesetterCreateWithAttributedString 创建带有中文字符串的框架设置器非常慢,但在 iOS4 中,它很快。

我已经进行了这样的测试:(chinese.txt 包含 77571 个中文字符,english.txt 包含 233727 个字符)

 NSString *englishCtn = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", [self documentDirectory], @"english.txt"] encoding:NSUTF8StringEncoding error:nil];
 NSAttributedString *englishCtnA = [[NSAttributedString alloc] initWithString:englishCtn];
 NSString *chineseCtn = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", [self documentDirectory], @"chinese.txt"] encoding:NSUTF8StringEncoding error:nil];
 NSAttributedString *chineseCtnA = [[NSAttributedString alloc] initWithString:chineseCtn];

double start = [[NSDate date] timeIntervalSince1970];
CTFramesetterCreateWithAttributedString((CFAttributedStringRef)englishCtnA);
NSLog(@"english length:%d time %f", englishCtn.length, ([[NSDate date] timeIntervalSince1970] - start) * 1000);

start = [[NSDate date] timeIntervalSince1970];
CTFramesetterCreateWithAttributedString((CFAttributedStringRef)chineseCtnA);
NSLog(@"chinese length:%d time %f", chineseCtnA.length, ([[NSDate date] timeIntervalSince1970] - start) * 1000);

在 iOS 5 中,结果是:

中文长度:77571 时间:12140.347004

英文长度:233727 时间:75.886011

在 iOS 4 中,结果是:

中文长度:77571 时间:53.114176

英文长度:233727 时间:55.696011

我使用xCode工具时间分析器看看会发生什么,我发现函数TRun::GetNextLigatureCandidateCharRange(long)占用大部分时间,我不知道如何优化,求助

4

1 回答 1

0

The C++ portions of the runtime were largely, if not entirely added in iOS 5, and that is where it fails. To me that suggests that you should file a bug report with apple, or open an inquiry on your account if you have any remaining.

于 2012-04-05T14:39:13.060 回答