[PATCH] resource: Remove a useless iteration
Adam Jackson
ajax at redhat.com
Mon Jan 10 09:44:23 PST 2011
v2: More aggressive loop rewrite pointed out by Daniel.
Signed-off-by: Adam Jackson <ajax at redhat.com>
---
dix/resource.c | 28 ++++++++++++----------------
1 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/dix/resource.c b/dix/resource.c
index 6bd2403..ed8cc35 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -380,9 +380,8 @@ void
GetXIDRange(int client, Bool server, XID *minp, XID *maxp)
{
XID id, maxid;
- ResourcePtr *resp;
- ResourcePtr res;
int i;
+ ResourcePtr res;
XID goodid;
id = (Mask)client << CLIENTOFFSET;
@@ -390,20 +389,17 @@ GetXIDRange(int client, Bool server, XID *minp, XID *maxp)
id |= client ? SERVER_BIT : SERVER_MINID;
maxid = id | RESOURCE_ID_MASK;
goodid = 0;
- for (resp = clientTable[client].resources, i = clientTable[client].buckets;
- --i >= 0;)
- {
- for (res = *resp++; res; res = res->next)
- {
- if ((res->id < id) || (res->id > maxid))
- continue;
- if (((res->id - id) >= (maxid - res->id)) ?
- (goodid = AvailableID(client, id, res->id - 1, goodid)) :
- !(goodid = AvailableID(client, res->id + 1, maxid, goodid)))
- maxid = res->id - 1;
- else
- id = res->id + 1;
- }
+
+ for (i = 0; i < clientTable[client].buckets; i++) {
+ res = clientTable[client].resources[i];
+ if ((res->id < id) || (res->id > maxid))
+ continue;
+ if (((res->id - id) >= (maxid - res->id)) ?
+ (goodid = AvailableID(client, id, res->id - 1, goodid)) :
+ !(goodid = AvailableID(client, res->id + 1, maxid, goodid)))
+ maxid = res->id - 1;
+ else
+ id = res->id + 1;
}
if (id > maxid)
id = maxid = 0;
--
1.7.3.4
More information about the xorg-devel
mailing list