Detect the presence of libdispatch and, if available, use it for collection

enumeration methods that take blocks as arguments. This allows us to implement
the NSEnumerationConcurrent option of those methods with minimal effort.

The searching methods on NSIndexSet and all the sorting methods are still
missing.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35010 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
thebeing 2012-03-27 17:05:19 +00:00
parent de00ca1cc4
commit a5c6cfa9f7
15 changed files with 22804 additions and 4578 deletions

View file

@ -7,6 +7,7 @@
#import <Foundation/NSData.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSLock.h>
#import <Foundation/NSSet.h>
#if defined(GNUSTEP_BASE_LIBRARY)
#import <Foundation/NSSerialization.h>
@ -23,20 +24,26 @@ int main()
# endif
# if __has_feature(blocks)
NSAutoreleasePool *arp = [NSAutoreleasePool new];
__block NSLock *fooLock = [NSLock new];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: @"foo",
@"key1", @"bar", @"key2", @"foo", @"key3", nil];
[dict enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop){
if ([obj isEqual: @"foo"]){ fooCount++;}}];
void(^enumBlock)(id,id,BOOL*) = ^(id key, id obj, BOOL *stop){
if ([obj isEqual: @"foo"]){ [fooLock lock]; fooCount++; [fooLock unlock];}};
[dict enumerateKeysAndObjectsUsingBlock: enumBlock];
PASS((2 == fooCount),
"Can enumerate dictionary using a block");
fooCount = 0;
[dict enumerateKeysAndObjectsWithOptions: NSEnumerationConcurrent
usingBlock: enumBlock];
PASS((2 == fooCount),
"Can enumerate dictionary concurrently using a block");
NSSet *fooKeys = [dict keysOfEntriesPassingTest: ^(id key, id obj, BOOL *stop){
return [obj isEqual: @"foo"];}];
PASS((([fooKeys count] == 2)
&& ([fooKeys containsObject: @"key1"])
&& ([fooKeys containsObject: @"key3"]))
, "Can use blocks as predicates.");
[fooLock release];
[arp release]; arp = nil;
# else
SKIP("No Blocks support in the compiler.")