Added private GSFastEnumeration header. This defines two macros that allow fast enumeration to be used inside GNUstep. Use, for example:
NSArray *a= [NSArray arrayWithObjects: @"a", @"b", @"c", nil];
FOR_IN(NSString*, o, a)
NSLog(@"%@", o);
END_FOR_IN(a)
This is equivalent to:
for (NSString *o in a)
{
NSLog(@"%@", o);
}
On clang, it will be expanded to exactly that. With GCC, it will be expanded to something equivalent to the code that Clang (or Apple GCC) would expand this to.
This is a private GNUstep header and is not intended for general use. Outside of GNUstep, please use fast enumeration directly.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29170 72102866-910b-0410-8b05-ffd578937521
2009-12-27 14:34:10 +00:00
|
|
|
|
|
|
|
#ifdef __clang__
|
|
|
|
#define FOR_IN(type, var, collection) \
|
2016-06-27 19:06:12 +00:00
|
|
|
for (type var in collection)\
|
|
|
|
{
|
Added private GSFastEnumeration header. This defines two macros that allow fast enumeration to be used inside GNUstep. Use, for example:
NSArray *a= [NSArray arrayWithObjects: @"a", @"b", @"c", nil];
FOR_IN(NSString*, o, a)
NSLog(@"%@", o);
END_FOR_IN(a)
This is equivalent to:
for (NSString *o in a)
{
NSLog(@"%@", o);
}
On clang, it will be expanded to exactly that. With GCC, it will be expanded to something equivalent to the code that Clang (or Apple GCC) would expand this to.
This is a private GNUstep header and is not intended for general use. Outside of GNUstep, please use fast enumeration directly.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29170 72102866-910b-0410-8b05-ffd578937521
2009-12-27 14:34:10 +00:00
|
|
|
#define END_FOR_IN(collection) }
|
|
|
|
#else
|
2021-03-26 20:03:48 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wattributes"
|
|
|
|
void objc_enumerationMutation(id);
|
|
|
|
#pragma GCC diagnostic pop
|
Added private GSFastEnumeration header. This defines two macros that allow fast enumeration to be used inside GNUstep. Use, for example:
NSArray *a= [NSArray arrayWithObjects: @"a", @"b", @"c", nil];
FOR_IN(NSString*, o, a)
NSLog(@"%@", o);
END_FOR_IN(a)
This is equivalent to:
for (NSString *o in a)
{
NSLog(@"%@", o);
}
On clang, it will be expanded to exactly that. With GCC, it will be expanded to something equivalent to the code that Clang (or Apple GCC) would expand this to.
This is a private GNUstep header and is not intended for general use. Outside of GNUstep, please use fast enumeration directly.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29170 72102866-910b-0410-8b05-ffd578937521
2009-12-27 14:34:10 +00:00
|
|
|
#define FOR_IN(type, var, c) \
|
|
|
|
do\
|
|
|
|
{\
|
2016-06-27 19:06:12 +00:00
|
|
|
type var;\
|
|
|
|
NSFastEnumerationState gs_##c##_enumState = { 0 };\
|
|
|
|
id gs_##c##_items[16];\
|
|
|
|
unsigned long gs_##c##_limit = \
|
|
|
|
[c countByEnumeratingWithState: &gs_##c##_enumState \
|
|
|
|
objects: gs_##c##_items \
|
|
|
|
count: 16];\
|
|
|
|
if (gs_##c##_limit)\
|
|
|
|
{\
|
|
|
|
unsigned long gs_startMutations = *gs_##c##_enumState.mutationsPtr;\
|
|
|
|
do {\
|
|
|
|
unsigned long gs_##c##counter = 0;\
|
|
|
|
do {\
|
|
|
|
if (gs_startMutations != *gs_##c##_enumState.mutationsPtr)\
|
|
|
|
{\
|
|
|
|
objc_enumerationMutation(c);\
|
|
|
|
}\
|
|
|
|
var = gs_##c##_enumState.itemsPtr[gs_##c##counter++];\
|
Added private GSFastEnumeration header. This defines two macros that allow fast enumeration to be used inside GNUstep. Use, for example:
NSArray *a= [NSArray arrayWithObjects: @"a", @"b", @"c", nil];
FOR_IN(NSString*, o, a)
NSLog(@"%@", o);
END_FOR_IN(a)
This is equivalent to:
for (NSString *o in a)
{
NSLog(@"%@", o);
}
On clang, it will be expanded to exactly that. With GCC, it will be expanded to something equivalent to the code that Clang (or Apple GCC) would expand this to.
This is a private GNUstep header and is not intended for general use. Outside of GNUstep, please use fast enumeration directly.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29170 72102866-910b-0410-8b05-ffd578937521
2009-12-27 14:34:10 +00:00
|
|
|
|
|
|
|
#define END_FOR_IN(c) \
|
2016-06-27 19:06:12 +00:00
|
|
|
} while (gs_##c##counter < gs_##c##_limit);\
|
|
|
|
} while ((gs_##c##_limit \
|
|
|
|
= [c countByEnumeratingWithState: &gs_##c##_enumState\
|
|
|
|
objects: gs_##c##_items\
|
|
|
|
count: 16]));\
|
|
|
|
}\
|
Added private GSFastEnumeration header. This defines two macros that allow fast enumeration to be used inside GNUstep. Use, for example:
NSArray *a= [NSArray arrayWithObjects: @"a", @"b", @"c", nil];
FOR_IN(NSString*, o, a)
NSLog(@"%@", o);
END_FOR_IN(a)
This is equivalent to:
for (NSString *o in a)
{
NSLog(@"%@", o);
}
On clang, it will be expanded to exactly that. With GCC, it will be expanded to something equivalent to the code that Clang (or Apple GCC) would expand this to.
This is a private GNUstep header and is not intended for general use. Outside of GNUstep, please use fast enumeration directly.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29170 72102866-910b-0410-8b05-ffd578937521
2009-12-27 14:34:10 +00:00
|
|
|
} while(0);
|
|
|
|
#endif
|