aboutsummaryrefslogtreecommitdiff
path: root/Foundation
diff options
context:
space:
mode:
Diffstat (limited to 'Foundation')
-rw-r--r--Foundation/GTMCalculatedRange.m9
-rw-r--r--Foundation/GTMFileSystemKQueue.m2
-rw-r--r--Foundation/GTMHTTPFetcher.m6
-rw-r--r--Foundation/GTMHTTPServer.m2
-rw-r--r--Foundation/GTMLightweightProxy.m4
-rw-r--r--Foundation/GTMLogger+ASL.m3
-rw-r--r--Foundation/GTMLogger.m3
-rw-r--r--Foundation/GTMNSAppleEventDescriptor+Foundation.m32
-rw-r--r--Foundation/GTMNSAppleEventDescriptor+FoundationTest.m2
-rw-r--r--Foundation/GTMNSArray+Merge.m3
-rw-r--r--Foundation/GTMNSDictionary+URLArguments.m4
-rw-r--r--Foundation/GTMNSFileManager+Path.m7
-rw-r--r--Foundation/GTMRegex.h4
-rw-r--r--Foundation/GTMRegex.m5
-rw-r--r--Foundation/GTMSignalHandler.m2
15 files changed, 47 insertions, 41 deletions
diff --git a/Foundation/GTMCalculatedRange.m b/Foundation/GTMCalculatedRange.m
index ef49d83..5ab491d 100644
--- a/Foundation/GTMCalculatedRange.m
+++ b/Foundation/GTMCalculatedRange.m
@@ -81,9 +81,8 @@ GTM_INLINE BOOL FPEqual(CGFloat a, CGFloat b) {
- (void)insertStop:(id)item atPosition:(CGFloat)position {
NSUInteger positionIndex = 0;
- NSEnumerator *theEnumerator = [storage_ objectEnumerator];
GTMCalculatedRangeStopPrivate *theStop;
- while (nil != (theStop = [theEnumerator nextObject])) {
+ GTM_FOREACH_OBJECT(theStop, storage_) {
if ([theStop position] < position) {
positionIndex += 1;
}
@@ -100,9 +99,8 @@ GTM_INLINE BOOL FPEqual(CGFloat a, CGFloat b) {
- (BOOL)removeStopAtPosition:(CGFloat)position {
NSUInteger positionIndex = 0;
BOOL foundStop = NO;
- NSEnumerator *theEnumerator = [storage_ objectEnumerator];
GTMCalculatedRangeStopPrivate *theStop;
- while (nil != (theStop = [theEnumerator nextObject])) {
+ GTM_FOREACH_OBJECT(theStop, storage_) {
if (FPEqual([theStop position], position)) {
break;
} else {
@@ -135,8 +133,7 @@ GTM_INLINE BOOL FPEqual(CGFloat a, CGFloat b) {
- (id)valueAtPosition:(CGFloat)position {
id theValue = nil;
GTMCalculatedRangeStopPrivate *theStop;
- NSEnumerator *theEnumerator = [storage_ objectEnumerator];
- while (nil != (theStop = [theEnumerator nextObject])) {
+ GTM_FOREACH_OBJECT(theStop, storage_) {
if (FPEqual([theStop position], position)) {
theValue = [theStop item];
break;
diff --git a/Foundation/GTMFileSystemKQueue.m b/Foundation/GTMFileSystemKQueue.m
index 050d68f..ebb2ec8 100644
--- a/Foundation/GTMFileSystemKQueue.m
+++ b/Foundation/GTMFileSystemKQueue.m
@@ -85,11 +85,13 @@ static CFSocketRef gRunLoopSocket = NULL;
return self;
}
+#if GTM_SUPPORT_GC
- (void)finalize {
[self unregisterWithKQueue];
[super finalize];
}
+#endif
- (void)dealloc {
[self unregisterWithKQueue];
diff --git a/Foundation/GTMHTTPFetcher.m b/Foundation/GTMHTTPFetcher.m
index 34821f2..c3be384 100644
--- a/Foundation/GTMHTTPFetcher.m
+++ b/Foundation/GTMHTTPFetcher.m
@@ -398,9 +398,8 @@ CannotBeginFetch:
// any headers in the redirect override headers in the original.
NSDictionary *redirectHeaders = [redirectRequest allHTTPHeaderFields];
if (redirectHeaders) {
- NSEnumerator *enumerator = [redirectHeaders keyEnumerator];
NSString *key;
- while (nil != (key = [enumerator nextObject])) {
+ GTM_FOREACH_KEY(key, redirectHeaders) {
NSString *value = [redirectHeaders objectForKey:key];
[newRequest setValue:value forHTTPHeaderField:key];
}
@@ -1198,10 +1197,9 @@ CannotBeginFetch:
[self removeExpiredCookiesInArray:cookieStorageArray];
- NSEnumerator *newCookieEnum = [newCookies objectEnumerator];
NSHTTPCookie *newCookie;
- while ((newCookie = [newCookieEnum nextObject]) != nil) {
+ GTM_FOREACH_OBJECT(newCookie, newCookies) {
if ([[newCookie name] length] > 0
&& [[newCookie domain] length] > 0
diff --git a/Foundation/GTMHTTPServer.m b/Foundation/GTMHTTPServer.m
index ecd649c..4ecc9f7 100644
--- a/Foundation/GTMHTTPServer.m
+++ b/Foundation/GTMHTTPServer.m
@@ -94,10 +94,12 @@ static NSString *kResponse = @"Response";
[super dealloc];
}
+#if GTM_SUPPORT_GC
- (void)finalize {
[self stop];
[super finalize];
}
+#endif
- (id)delegate {
return delegate_;
diff --git a/Foundation/GTMLightweightProxy.m b/Foundation/GTMLightweightProxy.m
index 39f5f5c..c00e44b 100644
--- a/Foundation/GTMLightweightProxy.m
+++ b/Foundation/GTMLightweightProxy.m
@@ -17,7 +17,7 @@
//
#import "GTMLightweightProxy.h"
-
+#import "GTMDefines.h"
@implementation GTMLightweightProxy
@@ -28,12 +28,14 @@
}
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
+#if GTM_SUPPORT_GC
// -[NSProxy finalize] is only in 10.5 or later
- (void)finalize {
representedObject_ = nil;
[super finalize];
}
#endif
+#endif
- (void)dealloc {
// it's weak, we don't release
diff --git a/Foundation/GTMLogger+ASL.m b/Foundation/GTMLogger+ASL.m
index 2213df6..90ea7e5 100644
--- a/Foundation/GTMLogger+ASL.m
+++ b/Foundation/GTMLogger+ASL.m
@@ -17,6 +17,7 @@
//
#import "GTMLogger+ASL.h"
+#import "GTMDefines.h"
@implementation GTMLogger (GTMLoggerASLAdditions)
@@ -107,10 +108,12 @@
[super dealloc];
}
+#if GTM_SUPPORT_GC
- (void)finalize {
if (client_) asl_close(client_);
[super finalize];
}
+#endif
// We don't test this one line because we don't want to pollute actual system
// logs with test messages.
diff --git a/Foundation/GTMLogger.m b/Foundation/GTMLogger.m
index 4da1034..de941d2 100644
--- a/Foundation/GTMLogger.m
+++ b/Foundation/GTMLogger.m
@@ -291,8 +291,7 @@ static GTMLogger *gSharedLogger = nil;
- (void)logMessage:(NSString *)msg level:(GTMLoggerLevel)level {
@synchronized(self) {
id<GTMLogWriter> child = nil;
- NSEnumerator *childEnumerator = [self objectEnumerator];
- while ((child = [childEnumerator nextObject])) {
+ GTM_FOREACH_OBJECT(child, self) {
if ([child conformsToProtocol:@protocol(GTMLogWriter)])
[child logMessage:msg level:level];
}
diff --git a/Foundation/GTMNSAppleEventDescriptor+Foundation.m b/Foundation/GTMNSAppleEventDescriptor+Foundation.m
index d0c26ec..b355607 100644
--- a/Foundation/GTMNSAppleEventDescriptor+Foundation.m
+++ b/Foundation/GTMNSAppleEventDescriptor+Foundation.m
@@ -100,15 +100,22 @@ static NSMutableDictionary *gTypeMap = nil;
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
NSAppleEventDescriptor *userRecord = [self descriptorForKeyword:keyASUserRecordFields];
if (userRecord) {
- NSEnumerator *userItems = [[userRecord gtm_arrayValue] objectEnumerator];
- NSString *key;
- while ((key = [userItems nextObject])) {
- NSString *value = [userItems nextObject];
- if (!value) {
- _GTMDevLog(@"Got a key %@ with no value in %@", key, userItems);
- return nil;
+ NSArray *userItems = [userRecord gtm_arrayValue];
+ NSString *key = nil;
+ NSString *item;
+ GTM_FOREACH_OBJECT(item, userItems) {
+ if (key) {
+ // Save the pair and reset our state
+ [dictionary setObject:item forKey:key];
+ key = nil;
+ } else {
+ // Save it for the next pair
+ key = item;
}
- [dictionary setObject:value forKey:key];
+ }
+ if (key) {
+ _GTMDevLog(@"Got a key %@ with no value in %@", key, userItems);
+ return nil;
}
} else {
NSUInteger count = [self numberOfItems];
@@ -291,10 +298,9 @@ static NSMutableDictionary *gTypeMap = nil;
}
- (NSAppleEventDescriptor*)gtm_appleEventDescriptor {
- NSEnumerator* keys = [self keyEnumerator];
Class keyClass = nil;
id key = nil;
- while ((key = [keys nextObject])) {
+ GTM_FOREACH_KEY(key, self) {
if (!keyClass) {
if ([key isKindOfClass:[GTMFourCharCode class]]) {
keyClass = [GTMFourCharCode class];
@@ -314,8 +320,7 @@ static NSMutableDictionary *gTypeMap = nil;
NSAppleEventDescriptor *desc = [NSAppleEventDescriptor recordDescriptor];
if ([keyClass isEqual:[NSString class]]) {
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[self count] * 2];
- keys = [self keyEnumerator];
- while ((key = [keys nextObject])) {
+ GTM_FOREACH_KEY(key, self) {
[array addObject:key];
[array addObject:[self objectForKey:key]];
}
@@ -325,8 +330,7 @@ static NSMutableDictionary *gTypeMap = nil;
}
[desc setDescriptor:userRecord forKeyword:keyASUserRecordFields];
} else {
- keys = [self keyEnumerator];
- while ((key = [keys nextObject])) {
+ GTM_FOREACH_KEY(key, self) {
id value = [self objectForKey:key];
NSAppleEventDescriptor *valDesc = [value gtm_appleEventDescriptor];
if (!valDesc) {
diff --git a/Foundation/GTMNSAppleEventDescriptor+FoundationTest.m b/Foundation/GTMNSAppleEventDescriptor+FoundationTest.m
index 6df19ab..f346e99 100644
--- a/Foundation/GTMNSAppleEventDescriptor+FoundationTest.m
+++ b/Foundation/GTMNSAppleEventDescriptor+FoundationTest.m
@@ -242,7 +242,7 @@
NSAppleEventDescriptor *userRecord = [array gtm_appleEventDescriptor];
STAssertNotNil(userRecord, @"");
[desc setDescriptor:userRecord forKeyword:keyASUserRecordFields];
- [GTMUnitTestDevLog expectPattern:@"Got a key bam with no value in <.*"];
+ [GTMUnitTestDevLog expectPattern:@"Got a key bam with no value in \\(.*"];
dictionary = [desc gtm_objectValue];
STAssertNil(dictionary, @"Should be nil");
}
diff --git a/Foundation/GTMNSArray+Merge.m b/Foundation/GTMNSArray+Merge.m
index da58a02..0c1582d 100644
--- a/Foundation/GTMNSArray+Merge.m
+++ b/Foundation/GTMNSArray+Merge.m
@@ -56,8 +56,7 @@
: nil;
id newItem = nil;
- NSEnumerator *itemEnum = [sortedNewArray objectEnumerator];
- while ((newItem = [itemEnum nextObject])) {
+ GTM_FOREACH_OBJECT(newItem, sortedNewArray) {
BOOL stillLooking = YES;
while (oldIndex < oldCount && stillLooking) {
// We must take care here, since Intel leaves junk in high bytes of
diff --git a/Foundation/GTMNSDictionary+URLArguments.m b/Foundation/GTMNSDictionary+URLArguments.m
index d67572c..89610e4 100644
--- a/Foundation/GTMNSDictionary+URLArguments.m
+++ b/Foundation/GTMNSDictionary+URLArguments.m
@@ -19,6 +19,7 @@
#import "GTMNSDictionary+URLArguments.h"
#import "GTMNSString+URLArguments.h"
#import "GTMMethodCheck.h"
+#import "GTMDefines.h"
@implementation NSDictionary (GTMNSDictionaryURLArgumentsAdditions)
@@ -26,9 +27,8 @@ GTM_METHOD_CHECK(NSString, gtm_stringByEscapingForURLArgument);
- (NSString *)gtm_httpArgumentsString {
NSMutableArray* arguments = [NSMutableArray arrayWithCapacity:[self count]];
- NSEnumerator* keyEnumerator = [self keyEnumerator];
NSString* key;
- while ((key = [keyEnumerator nextObject])) {
+ GTM_FOREACH_KEY(key, self) {
[arguments addObject:[NSString stringWithFormat:@"%@=%@",
[key gtm_stringByEscapingForURLArgument],
[[[self objectForKey:key] description] gtm_stringByEscapingForURLArgument]]];
diff --git a/Foundation/GTMNSFileManager+Path.m b/Foundation/GTMNSFileManager+Path.m
index 2d71729..195cd9e 100644
--- a/Foundation/GTMNSFileManager+Path.m
+++ b/Foundation/GTMNSFileManager+Path.m
@@ -17,6 +17,7 @@
//
#import "GTMNSFileManager+Path.h"
+#import "GTMDefines.h"
@implementation NSFileManager (GMFileManagerPathAdditions)
@@ -34,10 +35,9 @@
return YES;
NSString *actualPath = @"/";
- NSEnumerator *directoryEnumerator = [[path pathComponents] objectEnumerator];
NSString *directory;
- while ((directory = [directoryEnumerator nextObject])) {
+ GTM_FOREACH_OBJECT(directory, [path pathComponents]) {
actualPath = [actualPath stringByAppendingPathComponent:directory];
if ([self fileExistsAtPath:actualPath isDirectory:&isDir] && isDir) {
@@ -84,10 +84,9 @@
NSMutableArray *paths = [NSMutableArray arrayWithCapacity:[basenames count]];
NSString *basename;
- NSEnumerator *basenamesEnumerator = [basenames objectEnumerator];
// Convert all the |basenames| to full paths.
- while ((basename = [basenamesEnumerator nextObject])) {
+ GTM_FOREACH_OBJECT(basename, basenames) {
NSString *fullPath = [directoryPath stringByAppendingPathComponent:basename];
[paths addObject:fullPath];
}
diff --git a/Foundation/GTMRegex.h b/Foundation/GTMRegex.h
index c32eee2..3ef5604 100644
--- a/Foundation/GTMRegex.h
+++ b/Foundation/GTMRegex.h
@@ -84,12 +84,10 @@ _EXTERN NSString* kGTMRegexPatternErrorErrorString _INITIALIZE_AS(@"patternError
// Example usage:
//
// NSArray *inputArrayOfStrings = ...
-// NSEnumerator *enumerator = [inputArrayOfString objectEnumerator];
-// NSString *curStr = nil;
// NSArray *matches = [NSMutableArray array];
//
// GTMRegex *regex = [GTMRegex regexWithPattern:@"foo.*bar"];
-// while ((curStr = [enumerator nextObject]) != nil) {
+// for (NSString *curStr in inputArrayOfStrings) {
// if ([regex matchesString:curStr])
// [matches addObject:curStr];
// }
diff --git a/Foundation/GTMRegex.m b/Foundation/GTMRegex.m
index 71d5050..1027224 100644
--- a/Foundation/GTMRegex.m
+++ b/Foundation/GTMRegex.m
@@ -190,6 +190,7 @@ static NSString *const kReplacementPattern =
return self;
}
+#if GTM_SUPPORT_GC
- (void)finalize {
// we used pattern_ as our flag that we initialized the regex_t
if (pattern_) {
@@ -200,6 +201,7 @@ static NSString *const kReplacementPattern =
}
[super finalize];
}
+#endif
- (void)dealloc {
// we used pattern_ as our flag that we initialized the regex_t
@@ -390,9 +392,8 @@ static NSString *const kReplacementPattern =
// no replacements, they want to eat matches, nothing to do
} else {
// spin over the split up replacement
- NSEnumerator *replacementEnumerator = [replacements objectEnumerator];
GTMRegexStringSegment *replacementSegment = nil;
- while ((replacementSegment = [replacementEnumerator nextObject]) != nil) {
+ GTM_FOREACH_OBJECT(replacementSegment, replacements) {
if (![replacementSegment isMatch]) {
// not a match, raw text to put in
[result appendString:[replacementSegment string]];
diff --git a/Foundation/GTMSignalHandler.m b/Foundation/GTMSignalHandler.m
index edfff7d..557d8be 100644
--- a/Foundation/GTMSignalHandler.m
+++ b/Foundation/GTMSignalHandler.m
@@ -86,12 +86,14 @@ static CFSocketRef gRunLoopSocket = NULL;
return self;
}
+#if GTM_SUPPORT_GC
- (void)finalize {
[self unregisterWithKQueue];
[super finalize];
}
+#endif
- (void)dealloc {
[self unregisterWithKQueue];