Skip to content
This repository has been archived by the owner on Nov 30, 2019. It is now read-only.

Improves property setter performance by avoiding NSString when possible #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Project/UISS/UISSPropertySetter.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ - (SEL)findSelectorMatchingRegexp:(NSString *)regexp class:(Class <UIAppearance>
unsigned int count = 0;
Method *methods = class_copyMethodList(class, &count);

NSString *selectorPrefix = self.selectorPrefix;
const char *selectorPrefix = self.selectorPrefix.UTF8String;
size_t selectorPrefixLength = strlen(selectorPrefix);

for (int i = 0; i < count; i++) {
SEL selector = method_getName(methods[i]);
NSString *selectorString = NSStringFromSelector(selector);

if ([selectorString hasPrefix:selectorPrefix]) { // reducing the use of regular expression for performance reasons
BOOL hasPrefix = strncmp(selectorPrefix, sel_getName(selector), selectorPrefixLength) == 0;

if (hasPrefix) { // reducing the use of NSString & regular expression for performance reasons
NSString *selectorString = NSStringFromSelector(selector);

if ([selectorString rangeOfString:regexp options:NSRegularExpressionSearch].location != NSNotFound) {
// this favours selector with shorter label
// the purpose of this is to pick forState: instead of forStates:
Expand Down