Skip to content

Commit

Permalink
-Change: define BitArray_Test/Set/Clear as macros
Browse files Browse the repository at this point in the history
  • Loading branch information
miniupnp committed Apr 19, 2018
1 parent b21a503 commit f4264ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ uint16 Tools_RandomLCG_Range(uint16 min, uint16 max)
return ret;
}

#ifndef BITARRAY_MACROS
/**
* Test a bit in a bit array.
* @param array Bit array.
Expand Down Expand Up @@ -337,3 +338,4 @@ void BitArray_Clear(uint8 *array, uint16 index)
{
array[index >> 3] &= ~(1 << (index & 7));
}
#endif
8 changes: 8 additions & 0 deletions src/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ extern void Tools_Random_Seed(uint32 seed);
extern void Tools_RandomLCG_Seed(uint16 seed);
extern uint16 Tools_RandomLCG_Range(uint16 min, uint16 max);

#define BITARRAY_MACROS

#ifdef BITARRAY_MACROS
#define BitArray_Test(array, index) (((const uint8 *)(array))[(index) >> 3] & (1 << ((index) & 7)))
#define BitArray_Set(array, index) ((uint8 *)(array))[(index) >> 3] |= (1 << ((index) & 7))
#define BitArray_Clear(array, index) ((uint8 *)(array))[(index) >> 3] &= ~(1 << ((index) & 7))
#else
extern bool BitArray_Test(uint8 *array, uint16 index);
extern void BitArray_Set(uint8 *array, uint16 index);
extern void BitArray_Clear(uint8 *array, uint16 index);
#endif

#endif /* TOOLS_H */

0 comments on commit f4264ae

Please sign in to comment.