Fixed perf issue due to use of regex in +[RCTConvert NSURL:]

This commit is contained in:
Nick Lockwood 2015-08-10 07:03:52 -07:00
parent 59b974eafb
commit b489c9aa43
3 changed files with 24 additions and 18 deletions

View File

@ -142,7 +142,14 @@ typedef BOOL css_clip_t, css_backface_visibility_t;
RCT_EXTERN NSNumber *RCTConvertEnumValue(const char *, NSDictionary *, NSNumber *, id);
RCT_EXTERN NSNumber *RCTConvertMultiEnumValue(const char *, NSDictionary *, NSNumber *, id);
RCT_EXTERN NSArray *RCTConvertArrayValue(SEL, id);
RCT_EXTERN void RCTLogConvertError(id, const char *);
/**
* This macro is used for logging conversion errors. This is just used to
* avoid repeating the same boilerplate for every error message.
*/
#define RCTLogConvertError(json, typeName) \
RCTLogError(@"JSON value '%@' of type %@ cannot be converted to %@", \
json, [json classForCoder], typeName)
/**
* This macro is used for creating simple converter functions that just call
@ -165,7 +172,7 @@ RCT_CUSTOM_CONVERTER(type, name, [json getter])
return code; \
} \
@catch (__unused NSException *e) { \
RCTLogConvertError(json, #type); \
RCTLogConvertError(json, @#type); \
json = nil; \
return code; \
} \

View File

@ -16,12 +16,6 @@
@implementation RCTConvert
void RCTLogConvertError(id json, const char *type)
{
RCTLogError(@"JSON value '%@' of type '%@' cannot be converted to %s",
json, [json classForCoder], type);
}
RCT_CONVERTER(id, id, self)
RCT_CONVERTER(BOOL, BOOL, boolValue)
@ -53,11 +47,11 @@ RCT_CONVERTER(NSString *, NSString, description)
});
NSNumber *number = [formatter numberFromString:json];
if (!number) {
RCTLogConvertError(json, "a number");
RCTLogConvertError(json, @"a number");
}
return number;
} else if (json && json != (id)kCFNull) {
RCTLogConvertError(json, "a number");
RCTLogConvertError(json, @"a number");
}
return nil;
}
@ -97,7 +91,7 @@ RCT_CONVERTER(NSString *, NSString, description)
}
// Check if it has a scheme
if ([path rangeOfString:@"[a-zA-Z][a-zA-Z._-]+:" options:NSRegularExpressionSearch].location == 0) {
if ([path rangeOfString:@":"].location != NSNotFound) {
path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
URL = [NSURL URLWithString:path];
if (URL) {
@ -117,7 +111,7 @@ RCT_CONVERTER(NSString *, NSString, description)
return [NSURL fileURLWithPath:path];
}
@catch (__unused NSException *e) {
RCTLogConvertError(json, "a valid URL");
RCTLogConvertError(json, @"a valid URL");
return nil;
}
}
@ -162,7 +156,7 @@ RCT_CONVERTER(NSString *, NSString, description)
}
return date;
} else if (json && json != (id)kCFNull) {
RCTLogConvertError(json, "a date");
RCTLogConvertError(json, @"a date");
}
return nil;
}
@ -339,7 +333,7 @@ static void RCTConvertCGStructValue(const char *type, NSArray *fields, NSDiction
result[i] = [RCTConvert CGFloat:json[fields[i]]];
}
} else if (RCT_DEBUG && json && json != (id)kCFNull) {
RCTLogConvertError(json, type);
RCTLogConvertError(json, @(type));
}
}
@ -627,7 +621,7 @@ RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
}
else if (RCT_DEBUG && json && json != (id)kCFNull) {
RCTLogConvertError(json, "a color");
RCTLogConvertError(json, @"a color");
}
// Default color
@ -665,7 +659,7 @@ RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
path = [self NSString:json[@"uri"]];
scale = [self CGFloat:json[@"scale"]];
} else {
RCTLogConvertError(json, "an image");
RCTLogConvertError(json, @"an image");
}
NSURL *URL = [self NSURL:path];
@ -696,7 +690,7 @@ RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
} else if ([scheme isEqualToString:@"data"]) {
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:URL]];
} else {
RCTLogConvertError(json, "an image. Only local files or data URIs are supported");
RCTLogConvertError(json, @"an image. Only local files or data URIs are supported");
}
if (scale > 0) {

View File

@ -205,7 +205,12 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
}
cell.textLabel.text = stackFrame[@"methodName"];
cell.detailTextLabel.text = cell.detailTextLabel.text = [NSString stringWithFormat:@"%@:%@", [stackFrame[@"file"] lastPathComponent], stackFrame[@"lineNumber"]];
NSString *fileAndLine = stackFrame[@"file"];
if (fileAndLine) {
fileAndLine = [fileAndLine stringByAppendingFormat:@":%@", stackFrame[@"lineNumber"]];
cell.detailTextLabel.text = cell.detailTextLabel.text = fileAndLine;
}
return cell;
}