Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

isValueAcceptable is now a plain function with a static array of clas…

…s objects to avoid excessive allocations for each check
  • Loading branch information...
commit ed3ac848b181207ea5e34aeaa3062398897fe9d7 1 parent eea5c83
@gwk gwk authored
Showing with 13 additions and 15 deletions.
  1. +13 −15 src/FSN_categories.m
View
28 src/FSN_categories.m
@@ -22,34 +22,32 @@ BOOL httpCodeIsOfClass(int httpCode, FSNHTTPCodeClass httpClass) {
@implementation NSDictionary (FSN)
-- (NSString *)urlQueryString {
+BOOL isValueAcceptable(id val) {
+ static NSArray* acceptableValueClasses = nil;
+ if (!acceptableValueClasses) {
+ acceptableValueClasses = @[[NSArray class], [NSNumber class], [NSString class]];
+ }
+ for (Class klass in acceptableValueClasses) {
+ if ([val isKindOfClass:klass])
+ return YES;
+ }
+ return NO;
+};
+
+- (NSString *)urlQueryString {
NSMutableString *string = [NSMutableString string];
BOOL first = YES;
- NSArray *acceptableValueClasses = @[[NSArray class],
- [NSNumber class],
- [NSString class]];
-
- BOOL (^isValueAcceptable)(id) = ^(id val) {
- for (Class klass in acceptableValueClasses) {
- if ([val isKindOfClass:klass])
- return YES;
- }
- return NO;
- };
for (id key in self) {
id val = [self objectForKey:key];
-
if (![key isKindOfClass:[NSString class]] || !isValueAcceptable(val)) {
FSNLogError(@"skipping bad parameter: key class: %@ key: %@; value class: %@; value: %@",
[key class], key, [val class], val);
NSAssert(0, @"bad parameter type");
continue;
}
-
[string appendFormat:@"%@%@=%@", (first ? @"" : @"&"), [key urlEncodedString], [val urlEncodedString]];
-
first = NO;
}
return string;
Please sign in to comment.
Something went wrong with that request. Please try again.