dix: cache ResourceClientBits() value

The `LimitClient` is set once and for all at startup, whereas the
function `ResourceClientBits()` which returns the client field offset
within the XID based on the value of `LimitClient` can be called
repeatedly.

Small optimization, cache the result of `ilog2()`, that saves running
the same loop over and over each time `ResourceClientBits()` is called.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
This commit is contained in:
Olivier Fourdan 2018-11-30 13:09:53 +01:00 committed by Adam Jackson
parent 48b1af2718
commit c731165402

View File

@ -620,7 +620,12 @@ ilog2(int val)
unsigned int
ResourceClientBits(void)
{
return (ilog2(LimitClients));
static unsigned int cached = 0;
if (cached == 0)
cached = ilog2(LimitClients);
return cached;
}
/*****************