2012-04-05 45 views
3

我发现使用CTFramesetterCreateWithAttributedString在iOS5中使用中文字符串创建framesetter非常缓慢,但在iOS4中,速度很快。为什么用中文文本创建framesetter在iOS5中速度极慢

我已经运行这样的试验: (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工具时,Profiler来看看发生什么事,我发现功能TRUN :: GetNextLigatureCandidateCharRange(长)取最的时间,我不知道如何优化,帮助

回答

0

运行时的C++部分大部分(如果不是完全在iOS 5中添加的话),那就是失败的地方。对我而言,这意味着你应该向苹果提交一份错误报告,或者如果你有任何遗留问题,请在你的账户上打开一个查询。

+0

e ...我不知道你的意思 – bang 2012-04-05 14:48:09

+0

等等...是你的函数(GetNextLigature ...)还是运行时的? – borrrden 2012-04-05 14:52:41

+0

它是核心文本框架的一部分 – bang 2012-04-05 14:57:23