Skip to content
Browse files

Rewrote the matching engine to use NSPredicate instead of manually fl…

…ipping through each signature
  • Loading branch information...
1 parent 31d8dc8 commit d05200b4144551691a8abce414ef6c30df3d1a5e Nick Zitzmann committed Mar 16, 2011
Showing with 8 additions and 9 deletions.
  1. +8 −9 ABTrackerDatabase.m
View
17 ABTrackerDatabase.m
@@ -60,19 +60,18 @@ - (id)init
- (BOOL)isCookieATrackingCookie:(NSHTTPCookie *)cookie why:(NSString **)description
{
NSString *cookieName = [cookie name];
+ NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%K == YES AND %@ BEGINSWITH %K) OR (%K == NO AND %K == %@)", @"BeginsWith", cookieName, @"Name", @"BeginsWith", @"Name", cookieName];
+ NSArray *matchingSigs = [_signatures filteredArrayUsingPredicate:predicate];
- for (NSDictionary *sig in _signatures)
+ if (matchingSigs && matchingSigs.count)
{
- NSString *name = [sig objectForKey:@"Name"];
- BOOL beginsWith = [[sig objectForKey:@"BeginsWith"] boolValue];
- NSString *urDescription = [sig objectForKey:@"UserReadableDescription"];
-
- if ((beginsWith && [cookieName hasPrefix:name]) || (!beginsWith && [cookieName isEqualToString:name]))
+ if (description)
{
- if (description)
- *description = urDescription;
- return YES;
+ NSDictionary *sig = [matchingSigs objectAtIndex:0UL];
+
+ *description = [sig objectForKey:@"UserReadableDescription"];
}
+ return YES;
}
return NO;
}

0 comments on commit d05200b

Please sign in to comment.
Something went wrong with that request. Please try again.