mirror of
https://github.com/overte-org/overte.git
synced 2025-07-26 07:50:04 +02:00
Get rid of the log calls entirely; use the same code that we use for the ID
streamer.
This commit is contained in:
parent
37382304f7
commit
fd2893bf6d
1 changed files with 12 additions and 8 deletions
|
@ -47,11 +47,19 @@ IDStreamer::IDStreamer(Bitstream& stream) :
|
||||||
_bits(1) {
|
_bits(1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDStreamer::setBitsFromValue(int value) {
|
static int getBitsForHighestValue(int highestValue) {
|
||||||
_bits = 1;
|
// if this turns out to be a bottleneck, there are fancier ways to do it (get the position of the highest set bit):
|
||||||
while (value >= (1 << _bits) - 1) {
|
// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
|
||||||
_bits++;
|
int bits = 0;
|
||||||
|
while (highestValue != 0) {
|
||||||
|
bits++;
|
||||||
|
highestValue >>= 1;
|
||||||
}
|
}
|
||||||
|
return bits;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDStreamer::setBitsFromValue(int value) {
|
||||||
|
_bits = getBitsForHighestValue(value + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
IDStreamer& IDStreamer::operator<<(int value) {
|
IDStreamer& IDStreamer::operator<<(int value) {
|
||||||
|
@ -719,10 +727,6 @@ Bitstream& Bitstream::operator<(const TypeStreamer* streamer) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getBitsForHighestValue(int highestValue) {
|
|
||||||
return (highestValue == 0) ? 0 : 1 + (int)(log((double)highestValue) / log(2.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
Bitstream& Bitstream::operator>(TypeReader& reader) {
|
Bitstream& Bitstream::operator>(TypeReader& reader) {
|
||||||
QByteArray typeName;
|
QByteArray typeName;
|
||||||
*this >> typeName;
|
*this >> typeName;
|
||||||
|
|
Loading…
Reference in a new issue