From bc22eb32ee589ff1d5221c4828c414dc7adf34ac Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 16 Jul 2024 12:29:55 +0200 Subject: [PATCH] xkb: ProcXkbGetDeviceInfo(): consolidate buffers to reduce writes Putting both payload pieces into one buffer, so it can be written out with only one call. Signed-off-by: Enrico Weigelt, metux IT consult --- xkb/xkb.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/xkb/xkb.c b/xkb/xkb.c index 35ef9ed25..d7a19bdc3 100644 --- a/xkb/xkb.c +++ b/xkb/xkb.c @@ -6484,23 +6484,25 @@ ProcXkbGetDeviceInfo(ClientPtr client) } WriteToClient(client, SIZEOF(xkbGetDeviceInfoReply), &rep); - char *str = calloc(1, nameLen); - if (!str) + int sz = nameLen + rep.nBtnsRtrn * sizeof(xkbActionWireDesc); + char *buf = calloc(1, sz); + if (!buf) return BadAlloc; - XkbWriteCountedString(str, dev->name, client->swapped); - WriteToClient(client, nameLen, str); - free(str); - length -= nameLen; + char *walk = buf; + + XkbWriteCountedString(walk, dev->name, client->swapped); + walk += nameLen; if (rep.nBtnsRtrn > 0) { - int sz; - xkbActionWireDesc *awire; - - sz = rep.nBtnsRtrn * SIZEOF(xkbActionWireDesc); - awire = (xkbActionWireDesc *) &dev->button->xkb_acts[rep.firstBtnRtrn]; - WriteToClient(client, sz, awire); - length -= sz; + memcpy(walk, + &dev->button->xkb_acts[rep.firstBtnRtrn], + sizeof(xkbActionWireDesc)*rep.nBtnsRtrn); + walk += sizeof(xkbActionWireDesc)*rep.nBtnsRtrn; } + + WriteToClient(client, sz, buf); + length -= sz; + if (nDeviceLedFBs > 0) { status = SendDeviceLedFBs(dev, ledClass, ledID, length, client); if (status != Success)