toupper.c.patch   [plain text]


--- toupper.c.orig	Tue May 20 15:21:44 2003
+++ toupper.c	Tue Jun 17 17:49:05 2003
@@ -39,6 +39,10 @@
 
 #include <stdio.h>
 #include <rune.h>
+#include <stdlib.h>
+
+__private_extern__ int
+__compRuneEntry(const void *, const void *); // from runetype.c
 
 __ct_rune_t
 ___toupper(c)
@@ -46,17 +50,16 @@
 {
 	int x;
 	_RuneRange *rr = &_CurrentRuneLocale->mapupper_ext;
-	_RuneEntry *re = rr->ranges;
+	_RuneEntry *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);
-	}
+	re = (_RuneEntry *)bsearch(&c, rr->ranges, rr->nranges,
+	    sizeof(_RuneEntry), __compRuneEntry);
+
+	if (re)
+		return(re->map + c - re->min);
 
 	return(c);
 }