X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/59e0d9fe772464b93d835d2a2964457702469a43..3d9156a7a519a5e3aa1b92e9d9d4b991f1aed7ff:/locale/FreeBSD/toupper.c?ds=sidebyside diff --git a/locale/FreeBSD/toupper.c b/locale/FreeBSD/toupper.c index 44d6fde..bb7f36a 100644 --- a/locale/FreeBSD/toupper.c +++ b/locale/FreeBSD/toupper.c @@ -35,27 +35,32 @@ */ #include -__FBSDID("$FreeBSD: src/lib/libc/locale/toupper.c,v 1.8 2002/08/21 16:19:56 mike Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/locale/toupper.c,v 1.11 2004/07/29 06:16:19 tjr Exp $"); #include -#include +#include __ct_rune_t ___toupper(c) __ct_rune_t c; { - int x; - _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext; - _RuneEntry *re = rr->ranges; + size_t lim; + _RuneRange *rr = &_CurrentRuneLocale->__mapupper_ext; + _RuneEntry *base, *re; if (c < 0 || c == EOF) return(c); - for (x = 0; x < rr->nranges; ++x, ++re) { - if (c < re->min) - return(c); - if (c <= re->max) - return(re->map + c - re->min); + /* Binary search -- see bsearch.c for explanation. */ + base = rr->__ranges; + for (lim = rr->__nranges; lim != 0; lim >>= 1) { + re = base + (lim >> 1); + if (re->__min <= c && c <= re->__max) + return (re->__map + c - re->__min); + else if (c > re->__max) { + base = re + 1; + lim--; + } } return(c);