diff options
| author | Tim J. Robbins <tjr@FreeBSD.org> | 2004-05-09 13:04:49 +0000 |
|---|---|---|
| committer | Tim J. Robbins <tjr@FreeBSD.org> | 2004-05-09 13:04:49 +0000 |
| commit | 45a11576f37d7758e6c1560462be3121e864a35f (patch) | |
| tree | afc406ac8f57049a431f52b1be0185f862495301 /lib/libc | |
| parent | b17e85fede8175ebfdd112cedb546c252170be16 (diff) | |
Notes
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/locale/runetype.c | 16 | ||||
| -rw-r--r-- | lib/libc/locale/tolower.c | 19 | ||||
| -rw-r--r-- | lib/libc/locale/toupper.c | 19 |
3 files changed, 34 insertions, 20 deletions
diff --git a/lib/libc/locale/runetype.c b/lib/libc/locale/runetype.c index ec1c2ec2f4039..def216c07f036 100644 --- a/lib/libc/locale/runetype.c +++ b/lib/libc/locale/runetype.c @@ -44,21 +44,25 @@ unsigned long ___runetype(c) __ct_rune_t c; { - int x; + size_t lim; _RuneRange *rr = &_CurrentRuneLocale->runetype_ext; - _RuneEntry *re = rr->ranges; + _RuneEntry *base, *re; if (c < 0 || c == EOF) return(0L); - for (x = 0; x < rr->nranges; ++x, ++re) { - if (c < re->min) - return(0L); - if (c <= re->max) { + /* 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) { if (re->types) return(re->types[c - re->min]); else return(re->map); + } else if (c > re->max) { + base = re + 1; + lim--; } } diff --git a/lib/libc/locale/tolower.c b/lib/libc/locale/tolower.c index f8caecba79ab4..04f39925c0035 100644 --- a/lib/libc/locale/tolower.c +++ b/lib/libc/locale/tolower.c @@ -44,18 +44,23 @@ __ct_rune_t ___tolower(c) __ct_rune_t c; { - int x; + size_t lim; _RuneRange *rr = &_CurrentRuneLocale->maplower_ext; - _RuneEntry *re = rr->ranges; + _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); diff --git a/lib/libc/locale/toupper.c b/lib/libc/locale/toupper.c index 6ce67577cde17..b83365d401307 100644 --- a/lib/libc/locale/toupper.c +++ b/lib/libc/locale/toupper.c @@ -44,18 +44,23 @@ __ct_rune_t ___toupper(c) __ct_rune_t c; { - int x; + size_t lim; _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext; - _RuneEntry *re = rr->ranges; + _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); |
