{"thread":{"id":"11123","subject":"[PATCH] Simplify crud() in ident.c","startedAt":"2007-12-03T19:11:43Z","lastAt":"2007-12-03T22:55:53Z","messageCount":8,"participants":["Alex Riesen","Jakub Narebski","Johannes Schindelin","David Kastrup","Luke Lu"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"61813","messageId":"20071203191143.GB17671@steel.home","threadId":"11123","inReplyTo":null,"subject":"[PATCH] Simplify crud() in ident.c","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-12-03T19:11:43Z","receivedAt":"2007-12-03T19:11:43Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Signed-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n\nNoticed it accidentally.\n\n ident.c |   28 +++++++++-------------------\n 1 files changed, 9 insertions(+), 19 deletions(-)\n\ndiff --git a/ident.c b/ident.c\nindex 9b2a852..dbd0f52 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -113,25 +113,15 @@ static int add_raw(char *buf, size_t size, int offset, const char *str)\n \n static int crud(unsigned char c)\n {\n-\tstatic char crud_array[256];\n-\tstatic int crud_array_initialized = 0;\n-\n-\tif (!crud_array_initialized) {\n-\t\tint k;\n-\n-\t\tfor (k = 0; k <= 31; ++k) crud_array[k] = 1;\n-\t\tcrud_array[' '] = 1;\n-\t\tcrud_array['.'] = 1;\n-\t\tcrud_array[','] = 1;\n-\t\tcrud_array[':'] = 1;\n-\t\tcrud_array[';'] = 1;\n-\t\tcrud_array['<'] = 1;\n-\t\tcrud_array['>'] = 1;\n-\t\tcrud_array['\"'] = 1;\n-\t\tcrud_array['\\''] = 1;\n-\t\tcrud_array_initialized = 1;\n-\t}\n-\treturn crud_array[c];\n+\treturn  c <= 32  ||\n+\t\tc == '.' ||\n+\t\tc == ',' ||\n+\t\tc == ':' ||\n+\t\tc == ';' ||\n+\t\tc == '<' ||\n+\t\tc == '>' ||\n+\t\tc == '\"' ||\n+\t\tc == '\\'';\n }\n \n /*\n-- \n1.5.3.6.1022.g35305\n"},{"id":"61814","messageId":"m3lk8bv8du.fsf@roke.D-201","threadId":"11123","inReplyTo":"20071203191143.GB17671@steel.home","subject":"Re: [PATCH] Simplify crud() in ident.c","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-12-03T20:19:29Z","receivedAt":"2007-12-03T20:19:29Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Perhaps simplier, but isn't it slower?\n\n-- \nJakub Narebski\n"},{"id":"61815","messageId":"Pine.LNX.4.64.0712032046480.27959@racer.site","threadId":"11123","inReplyTo":"20071203191143.GB17671@steel.home","subject":"Re: [PATCH] Simplify crud() in ident.c","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-12-03T20:47:09Z","receivedAt":"2007-12-03T20:47:09Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 3 Dec 2007, Alex Riesen wrote:\n\n> diff --git a/ident.c b/ident.c\n> index 9b2a852..dbd0f52 100644\n> --- a/ident.c\n> +++ b/ident.c\n> @@ -113,25 +113,15 @@ static int add_raw(char *buf, size_t size, int offset, const char *str)\n>  \n>  static int crud(unsigned char c)\n>  {\n> -\tstatic char crud_array[256];\n> -\tstatic int crud_array_initialized = 0;\n> -\n> -\tif (!crud_array_initialized) {\n> -\t\tint k;\n> -\n> -\t\tfor (k = 0; k <= 31; ++k) crud_array[k] = 1;\n> -\t\tcrud_array[' '] = 1;\n> -\t\tcrud_array['.'] = 1;\n> -\t\tcrud_array[','] = 1;\n> -\t\tcrud_array[':'] = 1;\n> -\t\tcrud_array[';'] = 1;\n> -\t\tcrud_array['<'] = 1;\n> -\t\tcrud_array['>'] = 1;\n> -\t\tcrud_array['\"'] = 1;\n> -\t\tcrud_array['\\''] = 1;\n> -\t\tcrud_array_initialized = 1;\n> -\t}\n> -\treturn crud_array[c];\n> +\treturn  c <= 32  ||\n> +\t\tc == '.' ||\n> +\t\tc == ',' ||\n> +\t\tc == ':' ||\n> +\t\tc == ';' ||\n> +\t\tc == '<' ||\n> +\t\tc == '>' ||\n> +\t\tc == '\"' ||\n> +\t\tc == '\\'';\n\nOr enhance ctype.c.\n\nCiao,\nDscho\n"},{"id":"61822","messageId":"20071203213247.GC17671@steel.home","threadId":"11123","inReplyTo":"m3lk8bv8du.fsf@roke.D-201","subject":"Re: [PATCH] Simplify crud() in ident.c","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-12-03T21:32:47Z","receivedAt":"2007-12-03T21:32:47Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Jakub Narebski, Mon, Dec 03, 2007 21:19:29 +0100:\n> Perhaps simplier, but isn't it slower?\n\ndoubt it\n"},{"id":"61824","messageId":"20071203213702.GD17671@steel.home","threadId":"11123","inReplyTo":"Pine.LNX.4.64.0712032046480.27959@racer.site","subject":"Re: [PATCH] Simplify crud() in ident.c","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-12-03T21:37:02Z","receivedAt":"2007-12-03T21:37:02Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Johannes Schindelin, Mon, Dec 03, 2007 21:47:09 +0100:\n> On Mon, 3 Dec 2007, Alex Riesen wrote:\n> > +\treturn  c <= 32  ||\n> > +\t\tc == '.' ||\n> > +\t\tc == ',' ||\n> > +\t\tc == ':' ||\n> > +\t\tc == ';' ||\n> > +\t\tc == '<' ||\n> > +\t\tc == '>' ||\n> > +\t\tc == '\"' ||\n> > +\t\tc == '\\'';\n> \n> Or enhance ctype.c.\n> \n\nThat's be nice, but the \"crud\" conflicts with existing classification,\nso I'd have to change the is*-macros as well. Don't feel like it.\n\nI believe the code is never in hotpath anyway so the shorter the\nbetter.\n"},{"id":"61830","messageId":"Pine.LNX.4.64.0712032247140.27959@racer.site","threadId":"11123","inReplyTo":"20071203213702.GD17671@steel.home","subject":"Re: [PATCH] Simplify crud() in ident.c","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-12-03T22:48:19Z","receivedAt":"2007-12-03T22:48:19Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 3 Dec 2007, Alex Riesen wrote:\n\n> Johannes Schindelin, Mon, Dec 03, 2007 21:47:09 +0100:\n> > On Mon, 3 Dec 2007, Alex Riesen wrote:\n> > > +\treturn  c <= 32  ||\n> > > +\t\tc == '.' ||\n> > > +\t\tc == ',' ||\n> > > +\t\tc == ':' ||\n> > > +\t\tc == ';' ||\n> > > +\t\tc == '<' ||\n> > > +\t\tc == '>' ||\n> > > +\t\tc == '\"' ||\n> > > +\t\tc == '\\'';\n> > \n> > Or enhance ctype.c.\n> > \n> \n> That's be nice, but the \"crud\" conflicts with existing classification,\n> so I'd have to change the is*-macros as well. Don't feel like it.\n> \n> I believe the code is never in hotpath anyway so the shorter the\n> better.\n\nReally?\n\n\treturn !!strchr(\".,:;<>\\\"\\\\\", c);\n\nCiao,\nDscho\n"},{"id":"61831","messageId":"85zlwre6i2.fsf@lola.goethe.zz","threadId":"11123","inReplyTo":"Pine.LNX.4.64.0712032247140.27959@racer.site","subject":"Re: [PATCH] Simplify crud() in ident.c","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2007-12-03T22:52:05Z","receivedAt":"2007-12-03T22:52:05Z","isPatch":true,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> On Mon, 3 Dec 2007, Alex Riesen wrote:\n>\n>> Johannes Schindelin, Mon, Dec 03, 2007 21:47:09 +0100:\n>> > On Mon, 3 Dec 2007, Alex Riesen wrote:\n>> > > +\treturn  c <= 32  ||\n>> > > +\t\tc == '.' ||\n>> > > +\t\tc == ',' ||\n>> > > +\t\tc == ':' ||\n>> > > +\t\tc == ';' ||\n>> > > +\t\tc == '<' ||\n>> > > +\t\tc == '>' ||\n>> > > +\t\tc == '\"' ||\n>> > > +\t\tc == '\\'';\n>> > \n>> > Or enhance ctype.c.\n>> > \n>> \n>> That's be nice, but the \"crud\" conflicts with existing classification,\n>> so I'd have to change the is*-macros as well. Don't feel like it.\n>> \n>> I believe the code is never in hotpath anyway so the shorter the\n>> better.\n>\n> Really?\n>\n> \treturn !!strchr(\".,:;<>\\\"\\\\\", c);\n\nWhat happened to c <= 32?\n\n-- \nDavid Kastrup, Kriemhildstr. 15, 44793 Bochum\n"},{"id":"61833","messageId":"903B0E5A-32E2-4029-90C1-8C227BEDD03D@vicaya.com","threadId":"11123","inReplyTo":"m3lk8bv8du.fsf@roke.D-201","subject":"Re: [PATCH] Simplify crud() in ident.c","fromName":"Luke Lu","fromEmail":"git@vicaya.com","sentAt":"2007-12-03T22:55:53Z","receivedAt":"2007-12-03T22:55:53Z","isPatch":true,"sender":{"key":"git@vicaya.com","avatar":null},"body":"\nOn Dec 3, 2007, at 12:19 PM, Jakub Narebski wrote:\n\n> Perhaps simplier, but isn't it slower?\n\nActually it's faster on modern cpu with deep pipelines. The following  \nis simple test on my macbookpro (repeated 3 times and picked lowest  \none):\n\n$ time ./crudtest 1000000000\nold crud...\nreal    0m0.856s\nuser    0m0.839s\nsys     0m0.011s\n$ time ./crudtest 1000000000 simple\nnew crud...\nreal    0m0.431s\nuser    0m0.421s\nsys     0m0.007s\n\nNote: it's compiled with gcc -O2. -O3 gives the same timing; -O:  \nsimple crud has the same timing while the old crud is 10x slower; -O0  \n(off): the simple code is 50% slower than old crud (note: 10x less  \niterations):\n\n$ time ./crudtest0 100000000\nold crud...\nreal    0m0.659s\nuser    0m0.638s\nsys     0m0.008s\n$ time ./crudtest0 100000000 simple\nnew crud...\nreal    0m1.175s\nuser    0m1.149s\nsys     0m0.014s\n\nSince the default CFLAGS in git Makefile has -O2, the simple/new code  \nis faster by default.\n\n__Luke\n"}]}