diff options
author | Ulrich Drepper <drepper@redhat.com> | 2006-04-09 02:45:24 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2006-04-09 02:45:24 +0000 |
commit | ab9a9ff8a1db6e91ce2461069c709e68bd82d8eb (patch) | |
tree | e38d1cb8196af19131b1419b04025aed5c04ba03 /nis/nss_nis/nis-service.c | |
parent | 7960f2a7040874c63196657fa25d6ddda778cc67 (diff) | |
download | glibc-ab9a9ff8a1db6e91ce2461069c709e68bd82d8eb.tar.gz glibc-ab9a9ff8a1db6e91ce2461069c709e68bd82d8eb.tar.xz glibc-ab9a9ff8a1db6e91ce2461069c709e68bd82d8eb.zip |
* nis/nss_nis/nis-alias.c: Optimize use of yperr2nss. Avoid calling
it for YPERR_SUCCESS. Minor cleanups. Add __builtin_expect. * nis/nss_nis/nis-ethers.c: Likewise. * nis/nss_nis/nis-grp.c: Likewise. * nis/nss_nis/nis-hosts.c: Likewise. * nis/nss_nis/nis-initgroups.c: Likewise. * nis/nss_nis/nis-netgrp.c: Likewise. * nis/nss_nis/nis-network.c: Likewise. * nis/nss_nis/nis-proto.c: Likewise. * nis/nss_nis/nis-publickey.c: Likewise. * nis/nss_nis/nis-pwd.c: Likewise. * nis/nss_nis/nis-rpc.c: Likewise. * nis/nss_nis/nis-service.c: Likewise. * nis/nss_nis/nis-spwd.c: Likewise.
Diffstat (limited to 'nis/nss_nis/nis-service.c')
-rw-r--r-- | nis/nss_nis/nis-service.c | 103 |
1 files changed, 46 insertions, 57 deletions
diff --git a/nis/nss_nis/nis-service.c b/nis/nss_nis/nis-service.c index 1e879d04e3..51b668a90e 100644 --- a/nis/nss_nis/nis-service.c +++ b/nis/nss_nis/nis-service.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2001, 2002, 2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 1996-2004, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996. @@ -98,29 +98,26 @@ dosearch (int instatus, char *inkey, int inkeylen, char *inval, { struct search_t *req = (struct search_t *) indata; - if (instatus != YP_TRUE) + if (__builtin_expect (instatus != YP_TRUE, 0)) return 1; if (inkey && inkeylen > 0 && inval && invallen > 0) { - struct parser_data *pdata = (void *) req->buffer; - int parse_res; - char *p; - - if ((size_t) (invallen + 1) > req->buflen) + if (__builtin_expect ((size_t) (invallen + 1) > req->buflen, 0)) { *req->errnop = ERANGE; req->status = NSS_STATUS_TRYAGAIN; return 1; } - p = strncpy (req->buffer, inval, invallen); + char *p = strncpy (req->buffer, inval, invallen); req->buffer[invallen] = '\0'; while (isspace (*p)) ++p; - parse_res = _nss_files_parse_servent (p, req->serv, pdata, req->buflen, - req->errnop); + int parse_res = _nss_files_parse_servent (p, req->serv, + (void *) req->buffer, + req->buflen, req->errnop); if (parse_res == -1) { req->status = NSS_STATUS_TRYAGAIN; @@ -237,7 +234,7 @@ internal_nis_getservent_r (struct servent *serv, char *buffer, ++p; parse_res = _nss_files_parse_servent (p, serv, pdata, buflen, errnop); - if (parse_res == -1) + if (__builtin_expect (parse_res == -1, 0)) return NSS_STATUS_TRYAGAIN; data->next = data->next->next; } @@ -266,60 +263,56 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol, struct servent *serv, char *buffer, size_t buflen, int *errnop) { - enum nss_status status; - char *domain; - if (name == NULL) { *errnop = EINVAL; return NSS_STATUS_UNAVAIL; } - if (yp_get_default_domain (&domain)) + char *domain; + if (__builtin_expect (yp_get_default_domain (&domain), 0)) return NSS_STATUS_UNAVAIL; /* If the protocol is given, we could try if our NIS server knows about services.byservicename map. If yes, we only need one query. */ - char key[strlen (name) + (protocol ? strlen (protocol) : 0) + 2]; - char *cp, *result; - size_t keylen, len; - int int_len; + size_t keylen = strlen (name) + 1 + (protocol ? strlen (protocol) : 0); + char key[keylen + 1]; /* key is: "name/proto" */ - cp = stpcpy (key, name); - if (protocol) + char *cp = stpcpy (key, name); + if (protocol != NULL) { *cp++ = '/'; strcpy (cp, protocol); } - keylen = strlen (key); - status = yperr2nss (yp_match (domain, "services.byservicename", key, - keylen, &result, &int_len)); - len = int_len; + + char *result; + int int_len; + enum nss_status status = yperr2nss (yp_match (domain, + "services.byservicename", key, + keylen, &result, &int_len)); + size_t len = int_len; /* If we found the key, it's ok and parse the result. If not, fall through and parse the complete table. */ - if (status == NSS_STATUS_SUCCESS) + if (__builtin_expect (status == NSS_STATUS_SUCCESS, 1)) { - struct parser_data *pdata = (void *) buffer; - int parse_res; - char *p; - - if ((size_t) (len + 1) > buflen) + if (__builtin_expect ((size_t) (len + 1) > buflen, 0)) { free (result); *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } - p = strncpy (buffer, result, len); + char *p = strncpy (buffer, result, len); buffer[len] = '\0'; while (isspace (*p)) ++p; free (result); - parse_res = _nss_files_parse_servent (p, serv, pdata, - buflen, errnop); - if (parse_res < 0) + + int parse_res = _nss_files_parse_servent (p, serv, (void *) buffer, + buflen, errnop); + if (__builtin_expect (parse_res < 0, 0)) { if (parse_res == -1) return NSS_STATUS_TRYAGAIN; @@ -360,10 +353,8 @@ _nss_nis_getservbyport_r (int port, const char *protocol, struct servent *serv, char *buffer, size_t buflen, int *errnop) { - enum nss_status status; char *domain; - - if (yp_get_default_domain (&domain)) + if (__builtin_expect (yp_get_default_domain (&domain), 0)) return NSS_STATUS_UNAVAIL; /* If the protocol is given, we only need one query. @@ -372,48 +363,45 @@ _nss_nis_getservbyport_r (int port, const char *protocol, const char *proto = protocol != NULL ? protocol : "tcp"; do { + /* key is: "port/proto" */ char key[sizeof (int) * 3 + strlen (proto) + 2]; + size_t keylen = snprintf (key, sizeof (key), "%d/%s", ntohs (port), + proto); + char *result; - size_t keylen, len; int int_len; - - /* key is: "port/proto" */ - keylen = snprintf (key, sizeof (key), "%d/%s", ntohs (port), proto); - status = yperr2nss (yp_match (domain, "services.byname", key, - keylen, &result, &int_len)); - len = int_len; + enum nss_status status = yperr2nss (yp_match (domain, "services.byname", + key, keylen, &result, + &int_len)); + size_t len = int_len; /* If we found the key, it's ok and parse the result. If not, fall through and parse the complete table. */ if (status == NSS_STATUS_SUCCESS) { - struct parser_data *pdata = (void *) buffer; - int parse_res; - char *p; - - if ((size_t) (len + 1) > buflen) + if (__builtin_expect ((size_t) (len + 1) > buflen, 0)) { free (result); *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } - p = strncpy (buffer, result, len); + char *p = strncpy (buffer, result, len); buffer[len] = '\0'; while (isspace (*p)) ++p; free (result); - parse_res = _nss_files_parse_servent (p, serv, pdata, - buflen, errnop); - if (parse_res < 0) + int parse_res = _nss_files_parse_servent (p, serv, (void *) buffer, + buflen, errnop); + if (__builtin_expect (parse_res < 0, 0)) { if (parse_res == -1) return NSS_STATUS_TRYAGAIN; else return NSS_STATUS_NOTFOUND; } - else - return NSS_STATUS_SUCCESS; + + return NSS_STATUS_SUCCESS; } } while (protocol == NULL && (proto[0] == 't' ? (proto = "udp") : NULL)); @@ -434,7 +422,8 @@ _nss_nis_getservbyport_r (int port, const char *protocol, req.buflen = buflen; req.errnop = errnop; req.status = NSS_STATUS_NOTFOUND; - status = yperr2nss (yp_all (domain, "services.byname", &ypcb)); + enum nss_status status = yperr2nss (yp_all (domain, "services.byname", + &ypcb)); if (status != NSS_STATUS_SUCCESS) return status; |