[Xcb] [PATCH 1/5] auth: precompute authnameslen

Julien Danjou julien at danjou.info
Tue Apr 7 05:45:05 PDT 2009


Signed-off-by: Julien Danjou <julien at danjou.info>
---
 src/xcb_auth.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/xcb_auth.c b/src/xcb_auth.c
index 93a6f68..6046fc3 100644
--- a/src/xcb_auth.c
+++ b/src/xcb_auth.c
@@ -56,6 +56,13 @@ static char *authnames[N_AUTH_PROTOS] = {
     "MIT-MAGIC-COOKIE-1",
 };
 
+static int authnameslen[N_AUTH_PROTOS] = {
+#ifdef HASXDMAUTH
+    sizeof("XDM-AUTHORIZATION-1") - 1,
+#endif
+    sizeof("MIT-MAGIC-COOKIE-1") - 1,
+};
+
 static size_t memdup(char **dst, void *src, size_t len)
 {
     if(len)
@@ -70,7 +77,7 @@ static size_t memdup(char **dst, void *src, size_t len)
 
 static int authname_match(enum auth_protos kind, char *name, size_t namelen)
 {
-    if(strlen(authnames[kind]) != namelen)
+    if(authnameslen[kind] != namelen)
 	return 0;
     if(memcmp(authnames[kind], name, namelen))
 	return 0;
@@ -87,8 +94,6 @@ static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen,
     unsigned short family;
     char hostnamebuf[256];   /* big enough for max hostname */
     char dispbuf[40];   /* big enough to hold more than 2^64 base 10 */
-    int authnamelens[N_AUTH_PROTOS];
-    int i;
 
     family = FamilyLocal; /* 256 */
     switch(sockname->sa_family)
@@ -128,12 +133,10 @@ static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen,
         addrlen = strlen(addr);
     }
 
-    for (i = 0; i < N_AUTH_PROTOS; i++)
-	authnamelens[i] = strlen(authnames[i]);
     return XauGetBestAuthByAddr (family,
                                  (unsigned short) addrlen, addr,
                                  (unsigned short) strlen(dispbuf), dispbuf,
-                                 N_AUTH_PROTOS, authnames, authnamelens);
+                                 N_AUTH_PROTOS, authnames, authnameslen);
 }
 
 #ifdef HASXDMAUTH
-- 
1.6.2.2



More information about the Xcb mailing list