2012-04-05 56 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