[PATCH][STEP 2] ctype changes for removing locale structures

Wilco Dijkstra Wilco.Dijkstra@arm.com
Fri Feb 16 04:11:00 GMT 2018


Hi,

A few comments:

> To do this al inline functions are removed, and the source implementations
> test hard coded values of the given characters

Given many are just a few instructions when inlined, you definitely want to inline
them - it's going to be much faster than the existing implementation and smaller
than a function call as well.

 int
 isalnum (int c)
 {
+#ifdef _REENT_SMALL
+	return (isdigit(c) | islower(c) | isupper(c));

This should use inlined isalpha.

 int
 isalpha (int c)
 {
+#ifdef 	_REENT_SMALL
+	return (islower(c) | isupper(c));

Should do isupper (c | 0x20) and be inlined.

 int
 isupper (int c)
 {
+#ifdef _REENT_SMALL
+	return ((c > 0x40) && (c < 0x4B));

I think there are 26 characters in our alphabet...

 int
 isxdigit (int c)
 {
+#ifdef _REENT_SMALL
+	return ( ((c > 0x2F) && (c < 0x3A)) ||
+                 ((c > 0x40) && (c < 0x48)) ||
+	         ((c > 0x60) && (c < 0x68)) )?1:0;

Again use the trick to combine a-f and A-F.

 int
 ispunct (int c)
 {
+#ifdef _REENT_SMALL
+	return ( ((c > 0x20) && (c < 0x30)) ||
+	         ((c > 0x5A) && (c < 0x60)) ||
+	         ((c > 0x7A) && (c < 0x7F)) )?1:0;

This is best written like isalpha (c) || isdigit (c) || isctrl (c) ? 0 :1;
with inlining. This means you typically just test isalpha before returning.

WIlco


More information about the Newlib mailing list