I posted this a while ago, and no one objected, so I'm including it now, since it does reduce resource usage and removes one potential source of low-memory failure.
>From 03d8cfa74e36ad2e8daf6b412533aa37cc099363 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Thu, 25 Mar 2010 08:28:28 +0100 Subject: [PATCH] grep: remove unnecessary code * src/main.c (print_line_middle): Now that we use RE_ICASE (enabled in commit 70e23616, "dfa: rewrite handling of multibyte case_fold lexing"), this case-conversion code is useless and wasteful. Remove it. --- src/main.c | 30 +++--------------------------- 1 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/main.c b/src/main.c index 3fdcfb9..8c9e776 100644 --- a/src/main.c +++ b/src/main.c @@ -724,32 +724,10 @@ print_line_middle (const char *beg, const char *lim, size_t match_offset; const char *cur = beg; const char *mid = NULL; - char *buf; - const char *ibeg; - /* XXX - should not be needed anymore now that we use RE_ICASE. - Revisit after 2.6.x stabilizes. */ - if (match_icase -#ifdef MBS_SUPPORT - && MB_CUR_MAX == 1 -#endif - ) - { - int i = lim - beg; - - ibeg = buf = xmalloc(i); - while (--i >= 0) - buf[i] = tolower((unsigned char) beg[i]); - } - else - { - buf = NULL; - ibeg = beg; - } - - while ( lim > cur - && ((match_offset = execute(ibeg, lim - beg, &match_size, - ibeg + (cur - beg))) != (size_t) -1)) + while (cur < lim + && ((match_offset = execute(beg, lim - beg, &match_size, + beg + (cur - beg))) != (size_t) -1)) { char const *b = beg + match_offset; @@ -793,8 +771,6 @@ print_line_middle (const char *beg, const char *lim, cur = b + match_size; } - free (buf); /* XXX */ - if (only_matching) cur = lim; else if (mid) -- 1.7.0.3.513.gc8ed0
