* [RFC] [PATCH] clean up cclass
@ 2005-12-31 7:20 Alecs King
2005-12-31 21:26 ` Linus Torvalds
0 siblings, 1 reply; 2+ messages in thread
From: Alecs King @ 2005-12-31 7:20 UTC (permalink / raw)
To: linux-sparse
Is there a good reason to always add that '+ 1' in both initialization
and dereference of cclass?
This patch just remove that unnecessary '+ 1'.
Signed-off-by: Alecs King <alecsk@gmail.com>
diff --git a/tokenize.c b/tokenize.c
index 497da13..7464b5a 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -347,30 +347,30 @@ enum {
ValidSecond = 32,
};
-static const long cclass[257] = {
- ['0' + 1 ... '9' + 1] = Digit | Hex,
- ['A' + 1 ... 'D' + 1] = Letter | Hex,
- ['E' + 1] = Letter | Hex | Exp,
- ['F' + 1] = Letter | Hex,
- ['G' + 1 ... 'O' + 1] = Letter,
- ['P' + 1] = Letter | Exp,
- ['Q' + 1 ... 'Z' + 1] = Letter,
- ['a' + 1 ... 'd' + 1] = Letter | Hex,
- ['e' + 1] = Letter | Hex | Exp,
- ['f' + 1] = Letter | Hex,
- ['g' + 1 ... 'o' + 1] = Letter,
- ['p' + 1] = Letter | Exp,
- ['q' + 1 ... 'z' + 1] = Letter,
- ['_' + 1] = Letter,
- ['.' + 1] = Dot | ValidSecond,
- ['=' + 1] = ValidSecond,
- ['+' + 1] = ValidSecond,
- ['-' + 1] = ValidSecond,
- ['>' + 1] = ValidSecond,
- ['<' + 1] = ValidSecond,
- ['&' + 1] = ValidSecond,
- ['|' + 1] = ValidSecond,
- ['#' + 1] = ValidSecond,
+static const long cclass[256] = {
+ ['0' ... '9'] = Digit | Hex,
+ ['A' ... 'D'] = Letter | Hex,
+ ['E'] = Letter | Hex | Exp,
+ ['F'] = Letter | Hex,
+ ['G' ... 'O'] = Letter,
+ ['P'] = Letter | Exp,
+ ['Q' ... 'Z'] = Letter,
+ ['a' ... 'd'] = Letter | Hex,
+ ['e'] = Letter | Hex | Exp,
+ ['f'] = Letter | Hex,
+ ['g' ... 'o'] = Letter,
+ ['p'] = Letter | Exp,
+ ['q' ... 'z'] = Letter,
+ ['_'] = Letter,
+ ['.'] = Dot | ValidSecond,
+ ['='] = ValidSecond,
+ ['+'] = ValidSecond,
+ ['-'] = ValidSecond,
+ ['>'] = ValidSecond,
+ ['<'] = ValidSecond,
+ ['&'] = ValidSecond,
+ ['|'] = ValidSecond,
+ ['#'] = ValidSecond,
};
/*
@@ -394,7 +394,7 @@ static int get_one_number(int c, int nex
*p++ = c;
for (;;) {
- long class = cclass[next + 1];
+ long class = cclass[next];
if (!(class & (Dot | Digit | Letter)))
break;
if (p != buffer_end)
@@ -647,7 +647,7 @@ static int get_one_special(int c, stream
* Check for combinations
*/
value = c;
- if (cclass[next + 1] & ValidSecond) {
+ if (cclass[next] & ValidSecond) {
comb = combinations[0];
c1 = c; c2 = next; c3 = 0;
for (i = 0; i < NR_COMBINATIONS; i++) {
@@ -810,7 +810,7 @@ static int get_one_identifier(int c, str
buf[0] = c;
for (;;) {
next = nextchar(stream);
- if (!(cclass[next + 1] & (Letter | Digit)))
+ if (!(cclass[next] & (Letter | Digit)))
break;
if (len >= sizeof(buf))
break;
@@ -832,7 +832,7 @@ static int get_one_identifier(int c, str
static int get_one_token(int c, stream_t *stream)
{
- long class = cclass[c + 1];
+ long class = cclass[c];
if (class & Digit)
return get_one_number(c, nextchar(stream), stream);
if (class & Letter)
--
Alecs King
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [RFC] [PATCH] clean up cclass
2005-12-31 7:20 [RFC] [PATCH] clean up cclass Alecs King
@ 2005-12-31 21:26 ` Linus Torvalds
0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2005-12-31 21:26 UTC (permalink / raw)
To: Alecs King; +Cc: linux-sparse
On Sat, 31 Dec 2005, Alecs King wrote:
>
> Is there a good reason to always add that '+ 1' in both initialization
> and dereference of cclass?
EOF, aka -1.
Now, whether that's a good enough reason for ugly code, I don't know. You
could do the same by doing something like
static const struct {
long eof;
long c[256];
} cclass = { 0 , { ..sane initializer.. } };
and then using
cclass.c[next]
without the "+1". It might noe be strictly conforming, but it sure as hell
should work in practice.
Another (perhaps better) alternative is to change the #define of EOF from
-1 to 256, and then make sure that we don't rely on "next < 0" anywhere
(which we might do by changing the type to "unsigned int" and expecting
the compiler to complain.
Linus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-12-31 21:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-31 7:20 [RFC] [PATCH] clean up cclass Alecs King
2005-12-31 21:26 ` Linus Torvalds
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.