Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static NSRegularExpression initializations #106

Closed
glenyi opened this issue Jun 26, 2016 · 3 comments
Closed

Static NSRegularExpression initializations #106

glenyi opened this issue Jun 26, 2016 · 3 comments

Comments

@glenyi
Copy link
Contributor

glenyi commented Jun 26, 2016

For large markdown files, forming the regex can be slow and doesn't need to be initialized more than once. The following adds a large performance boost in MMSpanParser:

    static NSRegularExpression *regex;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        regex = [NSRegularExpression regularExpressionWithPattern:@"^(\\w+)://" options:0 error:nil];
    });

Same with the email link scanner:

    static NSRegularExpression *regex;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        regex = [NSRegularExpression regularExpressionWithPattern:@"^[-._0-9\\p{L}]+@[-\\p{L}0-9][-.\\p{L}0-9]*\\.\\p{L}+$"
                                                          options:NSRegularExpressionCaseInsensitive
                                                            error:nil];
    });
@mdiep
Copy link
Owner

mdiep commented Jun 26, 2016

Care to open a pull request?

@glenyi
Copy link
Contributor Author

glenyi commented Jun 26, 2016

Done :)

@mdiep
Copy link
Owner

mdiep commented Jun 27, 2016

Fixed by #107.

@mdiep mdiep closed this as completed Jun 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants