mirror of
https://gitlab.freedesktop.org/xorg/lib/libx11.git
synced 2026-05-08 18:28:06 +02:00
Refactor common code from XAddHost & XRemoveHost into single function
On the Xlib side, the only real difference is the mode flag we send to the server with the address, so just make that an argument to the function with the common code for packing the address into the request. (Aside from labels, gcc 4.7.2 generates identical code before & after this change due to inlining, verified via diff of gcc -S output.) Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
This commit is contained in:
parent
3292195a64
commit
7db74514e4
1 changed files with 14 additions and 39 deletions
53
src/Host.c
53
src/Host.c
|
|
@ -64,13 +64,11 @@ X Window System is a trademark of The Open Group.
|
|||
#endif
|
||||
#include "Xlibint.h"
|
||||
|
||||
int
|
||||
XAddHost (
|
||||
register Display *dpy,
|
||||
XHostAddress *host)
|
||||
static inline int
|
||||
changehost (Display *dpy, XHostAddress *host, BYTE mode)
|
||||
{
|
||||
register xChangeHostsReq *req;
|
||||
register int length;
|
||||
xChangeHostsReq *req;
|
||||
int length;
|
||||
XServerInterpretedAddress *siAddr;
|
||||
int addrlen;
|
||||
|
||||
|
|
@ -87,7 +85,7 @@ XAddHost (
|
|||
UnlockDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
req->mode = HostInsert;
|
||||
req->mode = mode;
|
||||
req->hostFamily = host->family;
|
||||
req->hostLength = addrlen;
|
||||
if (siAddr) {
|
||||
|
|
@ -103,43 +101,20 @@ XAddHost (
|
|||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
XAddHost (
|
||||
register Display *dpy,
|
||||
XHostAddress *host)
|
||||
{
|
||||
return changehost(dpy, host, HostInsert);
|
||||
}
|
||||
|
||||
int
|
||||
XRemoveHost (
|
||||
register Display *dpy,
|
||||
XHostAddress *host)
|
||||
{
|
||||
register xChangeHostsReq *req;
|
||||
register int length;
|
||||
XServerInterpretedAddress *siAddr;
|
||||
int addrlen;
|
||||
|
||||
siAddr = host->family == FamilyServerInterpreted ?
|
||||
(XServerInterpretedAddress *)host->address : NULL;
|
||||
addrlen = siAddr ?
|
||||
siAddr->typelength + siAddr->valuelength + 1 : host->length;
|
||||
|
||||
length = (addrlen + 3) & ~0x3; /* round up */
|
||||
|
||||
LockDisplay(dpy);
|
||||
GetReqExtra (ChangeHosts, length, req);
|
||||
if (!req) {
|
||||
UnlockDisplay(dpy);
|
||||
return 0;
|
||||
}
|
||||
req->mode = HostDelete;
|
||||
req->hostFamily = host->family;
|
||||
req->hostLength = addrlen;
|
||||
if (siAddr) {
|
||||
char *dest = (char *) NEXTPTR(req,xChangeHostsReq);
|
||||
memcpy(dest, siAddr->type, siAddr->typelength);
|
||||
dest[siAddr->typelength] = '\0';
|
||||
memcpy(dest + siAddr->typelength + 1,siAddr->value,siAddr->valuelength);
|
||||
} else {
|
||||
memcpy((char *) NEXTPTR(req,xChangeHostsReq), host->address, addrlen);
|
||||
}
|
||||
UnlockDisplay(dpy);
|
||||
SyncHandle();
|
||||
return 1;
|
||||
return changehost(dpy, host, HostDelete);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue