iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
BB9z
V2EX  ›  iDev

[性能] NSRegularExpression 最好重用

  •  
  •   BB9z ·
    BB9z · Jan 8, 2015 · 4716 views
    This topic created in 4151 days ago, the information mentioned may be changed or developed.
    NSRegularExpression 的创建非常非常耗时(至少在某些设备上)。在一台 5C 上实测结果显示,在一段总计消耗 CPU 24s 的列表滚动历程中,创建 NSRegularExpression 竟然占用了 17s (70%) 的时间,而之前猜测耗时的富文本绘制只占了不到 0.5s。
    4 replies    2015-01-22 22:18:29 +08:00
    Elethom
        1
    Elethom  
       Jan 8, 2015 via iPhone   ❤️ 1
    能重用的最好都重用, best practice 是將 init 寫入 getter 中, 方便重用且可以隨時釋放. 很多類似的東西例如 formatter 也是一樣, 創建非常耗時.
    fbr91
        2
    fbr91  
       Jan 16, 2015
    NSRegularExpression怎么重用 -。-
    dcty
        3
    dcty  
       Jan 22, 2015
    @fbr91
    + (NSRegularExpression *)URLExpression
    {
    static NSRegularExpression *urlExpression;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
    urlExpression = [NSRegularExpression regularExpressionWithPattern:urlExpressionString options:NSRegularExpressionCaseInsensitive error:nil];
    });
    return urlExpression;
    }
    fbr91
        4
    fbr91  
       Jan 22, 2015
    @dcty 3ks
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2543 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 15:59 · PVG 23:59 · LAX 08:59 · JFK 11:59
    ♥ Do have faith in what you're doing.