Merge pull request #2218 from mono/assignProjectConfigurtionFix
[mono.git] / mono / utils / monobitset.h
index 5bea9278394d1e7dd1a2f033c71cb2a47517807b..8abe83907ceeb5cbdb419f03c0a12bc92c0365e2 100644 (file)
@@ -2,7 +2,12 @@
 #define __MONO_BITSET_H__
 
 #include <glib.h>
+#ifdef SGEN_WITHOUT_MONO
+#include "mono/utils/mono-compiler.h"
+#define MONO_API
+#else
 #include <mono/utils/mono-publib.h>
+#endif
 
 /*
  * When embedding, you have to define MONO_ZERO_LEN_ARRAY before including any
@@ -33,13 +38,28 @@ enum {
 
 /* Fast access to bits which depends on the implementation of the bitset */
 #define mono_bitset_test_fast(set,n) ((set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)))
-#define mono_bitset_test_fast(set,n) ((set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)))
 #define mono_bitset_set_fast(set,n) do { (set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] |= ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)); } while (0)
 #define mono_bitset_clear_fast(set,n) do { (set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] &= ~((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)); } while (0)
 #define mono_bitset_get_fast(set,n) ((set)->data[(n)])
 
 #define mono_bitset_copyto_fast(src,dest) do { memcpy (&(dest)->data, &(src)->data, (dest)->size / 8); } while (0)
 
+#define MONO_BITSET_FOREACH(set,idx,/*stmt*/...) \
+       do \
+       { \
+               MonoBitSet *set__ = (set); \
+               for (int i__ = 0; i__ < set__->size / MONO_BITSET_BITS_PER_CHUNK; i__++) { \
+                       if (set__->data [i__]) { \
+                               for (int j__ = 0; j__ < MONO_BITSET_BITS_PER_CHUNK; j__++) { \
+                                       if (set__->data [i__] & ((gsize) 1 << j__)) { \
+                                               guint idx = j__ + i__ * MONO_BITSET_BITS_PER_CHUNK; \
+                                               __VA_ARGS__; \
+                                       } \
+                               } \
+                       } \
+               } \
+       } while (0)
+
 #define mono_bitset_union_fast(dest,src) do { \
     MonoBitSet *tmp_src = (src); \
     MonoBitSet *tmp_dest = (dest); \