* [PATCH] lib, net: make isodigit public and use it
@ 2013-04-10 9:23 Andy Shevchenko
2013-04-10 12:43 ` Denis Kirjanov
0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2013-04-10 9:23 UTC (permalink / raw)
To: Jason Baron, netdev, Trond Myklebust, Andrew Morton; +Cc: Andy Shevchenko
There are at least two users of isodigit. Let's make it a public function of
ctype.h.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/ctype.h | 6 ++++++
lib/dynamic_debug.c | 1 -
net/sunrpc/cache.c | 1 -
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/linux/ctype.h b/include/linux/ctype.h
index 8acfe31..653589e 100644
--- a/include/linux/ctype.h
+++ b/include/linux/ctype.h
@@ -61,4 +61,10 @@ static inline char _tolower(const char c)
return c | 0x20;
}
+/* Fast check for octal digit */
+static inline int isodigit(const char c)
+{
+ return c >= '0' && c <= '7';
+}
+
#endif
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 5276b99..4603245 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -281,7 +281,6 @@ static inline int parse_lineno(const char *str, unsigned int *val)
* allow the user to express a query which matches a format
* containing embedded spaces.
*/
-#define isodigit(c) ((c) >= '0' && (c) <= '7')
static char *unescape(char *str)
{
char *in = str;
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 05ea9ac..80fe5c8 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -1210,7 +1210,6 @@ EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall);
* key and content are both parsed by cache
*/
-#define isodigit(c) (isdigit(c) && c <= '7')
int qword_get(char **bpp, char *dest, int bufsize)
{
/* return bytes copied, or -1 on error */
--
1.8.2.rc0.22.gb3600c3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] lib, net: make isodigit public and use it
2013-04-10 9:23 [PATCH] lib, net: make isodigit public and use it Andy Shevchenko
@ 2013-04-10 12:43 ` Denis Kirjanov
2013-04-10 13:03 ` Andy Shevchenko
2013-04-10 13:05 ` David Laight
0 siblings, 2 replies; 4+ messages in thread
From: Denis Kirjanov @ 2013-04-10 12:43 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Jason Baron, netdev, Trond Myklebust, Andrew Morton
what about #define isoctal(c) (((c) & ~7) ?
On 4/10/13, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> There are at least two users of isodigit. Let's make it a public function
> of
> ctype.h.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> include/linux/ctype.h | 6 ++++++
> lib/dynamic_debug.c | 1 -
> net/sunrpc/cache.c | 1 -
> 3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/ctype.h b/include/linux/ctype.h
> index 8acfe31..653589e 100644
> --- a/include/linux/ctype.h
> +++ b/include/linux/ctype.h
> @@ -61,4 +61,10 @@ static inline char _tolower(const char c)
> return c | 0x20;
> }
>
> +/* Fast check for octal digit */
> +static inline int isodigit(const char c)
> +{
> + return c >= '0' && c <= '7';
> +}
> +
> #endif
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index 5276b99..4603245 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -281,7 +281,6 @@ static inline int parse_lineno(const char *str, unsigned
> int *val)
> * allow the user to express a query which matches a format
> * containing embedded spaces.
> */
> -#define isodigit(c) ((c) >= '0' && (c) <= '7')
> static char *unescape(char *str)
> {
> char *in = str;
> diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
> index 05ea9ac..80fe5c8 100644
> --- a/net/sunrpc/cache.c
> +++ b/net/sunrpc/cache.c
> @@ -1210,7 +1210,6 @@ EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall);
> * key and content are both parsed by cache
> */
>
> -#define isodigit(c) (isdigit(c) && c <= '7')
> int qword_get(char **bpp, char *dest, int bufsize)
> {
> /* return bytes copied, or -1 on error */
> --
> 1.8.2.rc0.22.gb3600c3
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] lib, net: make isodigit public and use it
2013-04-10 12:43 ` Denis Kirjanov
@ 2013-04-10 13:03 ` Andy Shevchenko
2013-04-10 13:05 ` David Laight
1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2013-04-10 13:03 UTC (permalink / raw)
To: Denis Kirjanov; +Cc: Jason Baron, netdev, Trond Myklebust, Andrew Morton
On Wed, 2013-04-10 at 16:43 +0400, Denis Kirjanov wrote:
> what about #define isoctal(c) (((c) & ~7) ?
Few reasons why not:
- the name isodigit is used already
- above name is more logical to existing isdigit & isxdigit
- macro is usually worse than inline function
- your implementation is not strict to octal digits
>
> On 4/10/13, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > There are at least two users of isodigit. Let's make it a public function
> > of
> > ctype.h.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> > include/linux/ctype.h | 6 ++++++
> > lib/dynamic_debug.c | 1 -
> > net/sunrpc/cache.c | 1 -
> > 3 files changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/linux/ctype.h b/include/linux/ctype.h
> > index 8acfe31..653589e 100644
> > --- a/include/linux/ctype.h
> > +++ b/include/linux/ctype.h
> > @@ -61,4 +61,10 @@ static inline char _tolower(const char c)
> > return c | 0x20;
> > }
> >
> > +/* Fast check for octal digit */
> > +static inline int isodigit(const char c)
> > +{
> > + return c >= '0' && c <= '7';
> > +}
> > +
> > #endif
> > diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> > index 5276b99..4603245 100644
> > --- a/lib/dynamic_debug.c
> > +++ b/lib/dynamic_debug.c
> > @@ -281,7 +281,6 @@ static inline int parse_lineno(const char *str, unsigned
> > int *val)
> > * allow the user to express a query which matches a format
> > * containing embedded spaces.
> > */
> > -#define isodigit(c) ((c) >= '0' && (c) <= '7')
> > static char *unescape(char *str)
> > {
> > char *in = str;
> > diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
> > index 05ea9ac..80fe5c8 100644
> > --- a/net/sunrpc/cache.c
> > +++ b/net/sunrpc/cache.c
> > @@ -1210,7 +1210,6 @@ EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall);
> > * key and content are both parsed by cache
> > */
> >
> > -#define isodigit(c) (isdigit(c) && c <= '7')
> > int qword_get(char **bpp, char *dest, int bufsize)
> > {
> > /* return bytes copied, or -1 on error */
> > --
> > 1.8.2.rc0.22.gb3600c3
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe netdev" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> >
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 4+ messages in thread* RE: [PATCH] lib, net: make isodigit public and use it
2013-04-10 12:43 ` Denis Kirjanov
2013-04-10 13:03 ` Andy Shevchenko
@ 2013-04-10 13:05 ` David Laight
1 sibling, 0 replies; 4+ messages in thread
From: David Laight @ 2013-04-10 13:05 UTC (permalink / raw)
To: Denis Kirjanov, Andy Shevchenko
Cc: Jason Baron, netdev, Trond Myklebust, Andrew Morton
> what about #define isoctal(c) (((c) & ~7) ?
I presume you meant (((c) & ~7) == '0')
Actually the compiler will convert:
c >= '0' && c <= '7';
into
(unsigned)(c - '0') <= '7' - '0';
so it makes no significant difference.
Whether adding it to ctype.h is a good idea is a different
problem for the C standards people.
David
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-04-10 13:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-10 9:23 [PATCH] lib, net: make isodigit public and use it Andy Shevchenko
2013-04-10 12:43 ` Denis Kirjanov
2013-04-10 13:03 ` Andy Shevchenko
2013-04-10 13:05 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox