summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authordominik <dominik@openttd.org>2004-08-23 10:59:03 +0000
committerdominik <dominik@openttd.org>2004-08-23 10:59:03 +0000
commita6f2257600b8818ceff54c4f2b7fee376f11cfe6 (patch)
tree03f736144e43a70ff9b3aaca01c983b5bc7d282c /misc.c
parentcce45b44d8575bc60fe4b3c77c63987e40fc355a (diff)
downloadopenttd-a6f2257600b8818ceff54c4f2b7fee376f11cfe6.tar.xz
(svn r117) Feature: Performance details window in company league menu (TrueLight)
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/misc.c b/misc.c
index 06e790019..5f86d8445 100644
--- a/misc.c
+++ b/misc.c
@@ -601,11 +601,18 @@ void IncreaseDate()
/* XXX: check if year 2050 was reached */
}
-int FindFirstBit(uint32 x)
+int FindFirstBit(uint32 value)
{
- int i = 0;
- assert(x != 0);
- for(;!(x&1);i++,x>>=1);
+ // This is much faster then the one that was before here.
+ // Created by Darkvater.. blame him if it is wrong ;)
+ // Btw, the macro FINDFIRSTBIT is better to use when your value is
+ // not more then 128.
+ byte i = 0;
+ if (value & 0xffff0000) { value >>= 16; i += 16; }
+ if (value & 0x0000ff00) { value >>= 8; i += 8; }
+ if (value & 0x000000f0) { value >>= 4; i += 4; }
+ if (value & 0x0000000c) { value >>= 2; i += 2; }
+ if (value & 0x00000002) { i += 1; }
return i;
}