Remove all the range checking from Bitmap

This commit is contained in:
Eryn Wells 2016-04-16 01:24:28 -04:00
parent 99d3e85ba5
commit 1daa3df74e

View file

@ -43,39 +43,29 @@ struct Bitmap
isSet(usize bit) isSet(usize bit)
const const
{ {
if (isValid(bit)) { return (mBitmap & FieldType(1 << bit)) > 0;
return (mBitmap & (1 << bit)) > 0;
}
return false;
} }
/** Set a single bit to 1. */ /** Set a single bit to 1. */
void void
set(usize bit) set(usize bit)
{ {
if (isValid(bit)) { mBitmap |= FieldType(1 << bit);
mBitmap |= 1 << bit;
}
} }
/** Set a single bit to zero. */ /** Set a single bit to zero. */
void void
clear(usize bit) clear(usize bit)
{ {
if (isValid(bit)) { mBitmap &= ~FieldType(1 << bit);
mBitmap &= ~(1 << bit);
}
} }
/** Toggle the state of a single bit. Returns `true` if the bit was set to 1. */ /** Toggle the state of a single bit. Returns `true` if the bit was set to 1. */
bool bool
toggle(usize bit) toggle(usize bit)
{ {
if (isValid(bit)) { mBitmap ^= FieldType(1 << bit);
mBitmap ^= 1 << bit; return isSet(bit);
return isSet(bit);
}
return false;
} }
/** Clear the entire bit field. */ /** Clear the entire bit field. */
@ -101,13 +91,6 @@ struct Bitmap
private: private:
FieldType mBitmap; FieldType mBitmap;
inline bool
isValid(usize bit)
const
{
return bit >= 0 && bit < Bitmap::length;
}
}; };
} /* namespace kstd */ } /* namespace kstd */