From 610743864782fb55835cc7f7383573caecf41e2c Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 17 Jul 2024 13:18:10 +0200 Subject: [PATCH] (cleanup/xext-xres) Xext: xres: ProcXResQueryClientResources() simplify payload write out Collect the few bits in a local array, so one WriteToClient() call is sufficient. That's also easing further simplifications in upcoming commits. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/xres.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Xext/xres.c b/Xext/xres.c index 5b00da5fd..c2616e2bb 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -314,10 +314,13 @@ ProcXResQueryClientResources(ClientPtr client) FindAllClientResources(resClient, ResFindAllRes, counts); - int num_types = 0; - for (int i = 0; i <= lastResourceType; i++) { - if (counts[i]) + int cnt[lastResourceType + 1]; + + for (i = 0; i <= lastResourceType; i++) { + if (counts[i]) { + cnt[num_types] = counts[i]; num_types++; + } } xXResQueryClientResourcesReply rep = { @@ -332,10 +335,11 @@ ProcXResQueryClientResources(ClientPtr client) swapl(&rep.num_types); } - WriteToClient(client, sizeof(xXResQueryClientResourcesReply), &rep); + xXResType scratch[num_types]; - if (num_types) { - xXResType scratch; + for (i = 0; i < num_types; i++) { + scratch[i].resource_type = resourceTypeAtom(i + 1); + scratch[i].count = cnt[i]; for (int i = 0; i < lastResourceType; i++) { if (!counts[i]) @@ -352,8 +356,9 @@ ProcXResQueryClientResources(ClientPtr client) } } + WriteToClient(client, sizeof(xXResQueryClientResourcesReply), &rep); + WriteToClient(client, sizeof(scratch), scratch); free(counts); - return Success; }