iphone - 为什么在 iOS5 中用中文创建 framesetter 非常慢

标签 iphone objective-c ios core-text

我发现在 iOS5 中使用 CTFramesetterCreateWithAttributedString 创建带有中文字符串的 framesetter 非常慢,但在 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工具time profiler看看会发生什么,我发现函数TRun::GetNextLigatureCandidateCharRange(long)占用了大部分时间,我不知道如何优化,求助

最佳答案

运行时的 C++ 部分大部分(如果不是全部)添加到 iOS 5 中,这就是它失败的地方。对我来说,这表明您应该向 Apple 提交错误报告,或者在您的帐户上进行查询(如果还有剩余)。

关于iphone - 为什么在 iOS5 中用中文创建 framesetter 非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10029736/

相关文章:

iphone - NSString 比较抛出异常 SIGABT

iphone - SIGKILL 信号在 iPhone sim 上启动应用程序,但不是 Xcode

iphone - 网址中的mp3较长,无法在iPhone上加载太长

objective-c - 如何调试引用项目中的崩溃?

ios - xcode 以编程方式展开 segue

ios - 在 UIView 中居中 CAShapeLayer?

iphone - iOS 编程建议请求 REF sqlite/iOS 应用程序设计

ios - 如何使用 Facebook 个人资料照片填充我的 UITableView

ios - 如何使用 Core Graphics 在 iOS 中计算和绘制尺寸线(具有垂直端线的线)?

objective-c - MPMoviePlayerViewController 无法设置当前播放时间