This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH][STEP 2] ctype changes for removing locale structures
- From: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- To: "info at jasoon dot nl" <info at jasoon dot nl>
- Cc: nd <nd at arm dot com>, "newlib at sourceware dot org" <newlib at sourceware dot org>
- Date: Fri, 16 Feb 2018 04:11:29 +0000
- Subject: Re: [PATCH][STEP 2] ctype changes for removing locale structures
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco dot Dijkstra at arm dot com;
- Nodisclaimer: True
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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