From 1d8ebcdff42b2944a9e8aa1743362eebfa8e429a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Piotr=20C=C5=82apa?= Date: Fri, 20 Feb 2015 19:31:38 +0100 Subject: [PATCH] Change the printing algorithm from O(n^2) to O(n). --- exportCookies/CookiesTXT.m | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/exportCookies/CookiesTXT.m b/exportCookies/CookiesTXT.m index da37d6a..22e2977 100644 --- a/exportCookies/CookiesTXT.m +++ b/exportCookies/CookiesTXT.m @@ -12,16 +12,7 @@ @implementation CookiesTXT @synthesize cookieArray; -- (NSString *) entryFromArray:(NSArray *)arr { - return [arr componentsJoinedByString:@"\t"]; -} - -- (void) appendEntry:(NSString *)entry toTxt:(NSString **)txt { - *txt = [*txt stringByAppendingString:[entry stringByAppendingString:@"\n"]]; -} - - (void) print { - NSString *txt = @""; for (NSHTTPCookie *cookie in self.cookieArray) { NSMutableArray *entry = [NSMutableArray arrayWithCapacity:8]; [entry addObject:[cookie domain]]; @@ -31,10 +22,8 @@ - (void) print { [entry addObject:[NSString stringWithFormat:@"%.0f", [[cookie expiresDate] timeIntervalSince1970]]]; [entry addObject:[cookie name]]; [entry addObject:[cookie value]]; - [self appendEntry:[self entryFromArray:entry] toTxt:&txt]; - } - if (txt) { - printf("%s", [txt UTF8String]); + NSString *str = [[entry componentsJoinedByString:@"\t"] stringByAppendingString:@"\n"]; + printf("%s", [str UTF8String]); } }