From owner-svn-src-user@FreeBSD.ORG Wed Aug 10 19:40:24 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 33CAA106567C; Wed, 10 Aug 2011 19:40:24 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 249068FC0A; Wed, 10 Aug 2011 19:40:24 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p7AJeOT7058707; Wed, 10 Aug 2011 19:40:24 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7AJeO7F058705; Wed, 10 Aug 2011 19:40:24 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201108101940.p7AJeO7F058705@svn.freebsd.org> From: Gabor Kovesdan Date: Wed, 10 Aug 2011 19:40:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r224764 - user/gabor/tre-integration/contrib/tre/lib X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2011 19:40:24 -0000 Author: gabor Date: Wed Aug 10 19:40:23 2011 New Revision: 224764 URL: http://svn.freebsd.org/changeset/base/224764 Log: - Align backslashes of macros - Defer copying of pattern after all checks are passed; this also makes the code easier to read Modified: user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Modified: user/gabor/tre-integration/contrib/tre/lib/fastmatch.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Wed Aug 10 19:16:04 2011 (r224763) +++ user/gabor/tre-integration/contrib/tre/lib/fastmatch.c Wed Aug 10 19:40:23 2011 (r224764) @@ -60,37 +60,37 @@ static int fastcmp(const void *, const v * so we can handle MB strings as byte sequences just like * SB strings. */ -#define SKIP_CHARS(n) \ - do { \ - switch (type) \ - { \ - case STR_WIDE: \ - startptr = str_wide + n; \ - break; \ - default: \ - startptr = str_byte + n; \ - } \ - } while (0); \ +#define SKIP_CHARS(n) \ + do { \ + switch (type) \ + { \ + case STR_WIDE: \ + startptr = str_wide + n; \ + break; \ + default: \ + startptr = str_byte + n; \ + } \ + } while (0); \ /* * Converts the wide string pattern to SB/MB string and stores * it in fg->pattern. Sets fg->len to the byte length of the * converted string. */ -#define STORE_MBS_PAT \ - do { \ - size_t siz; \ - \ - siz = wcstombs(NULL, fg->wpattern, 0); \ - if (siz == (size_t)-1) \ - return REG_BADPAT; \ - fg->len = siz; \ - fg->pattern = xmalloc(siz + 1); \ - if (fg->pattern == NULL) \ - return REG_ESPACE; \ - wcstombs(fg->pattern, fg->wpattern, siz); \ - fg->pattern[siz] = '\0'; \ - } while (0); \ +#define STORE_MBS_PAT \ + do { \ + size_t siz; \ + \ + siz = wcstombs(NULL, fg->wpattern, 0); \ + if (siz == (size_t)-1) \ + return REG_BADPAT; \ + fg->len = siz; \ + fg->pattern = xmalloc(siz + 1); \ + if (fg->pattern == NULL) \ + return REG_ESPACE; \ + wcstombs(fg->pattern, fg->wpattern, siz); \ + fg->pattern[siz] = '\0'; \ + } while (0); \ /* * Compares the pattern to the input string at the position @@ -374,63 +374,57 @@ tre_fastcomp(fastmatch_t *fg, const tre_ if (fg->icase && (MB_CUR_MAX > 1)) return REG_BADPAT; - fg->wlen = (n == 0) ? tre_strlen(pat) : n; + n = (n == 0) ? tre_strlen(pat) : n; /* Remove end-of-line character ('$'). */ - if ((fg->wlen > 0) && (pat[fg->wlen - 1] == TRE_CHAR('$'))) + if ((n > 0) && (pat[n - 1] == TRE_CHAR('$'))) { fg->eol = true; - fg->wlen--; + n--; } /* Remove beginning-of-line character ('^'). */ if (pat[0] == TRE_CHAR('^')) { fg->bol = true; - fg->wlen--; + n--; pat++; } - if ((fg->wlen >= 14) && + if ((n >= 14) && (memcmp(pat, TRE_CHAR("[[:<:]]"), 7 * sizeof(tre_char_t)) == 0) && - (memcmp(pat + fg->wlen - 7, TRE_CHAR("[[:>:]]"), + (memcmp(pat + n - 7, TRE_CHAR("[[:>:]]"), 7 * sizeof(tre_char_t)) == 0)) { - fg->wlen -= 14; + n -= 14; pat += 7; fg->word = true; } - /* - * pat has been adjusted earlier to not include '^', '$' or - * the word match character classes at the beginning and ending - * of the string respectively. - */ - SAVE_PATTERN(fg->wpattern, fg->wlen); - /* Look for ways to cheat...er...avoid the full regex engine. */ - for (unsigned int i = 0; i < fg->wlen; i++) { + for (unsigned int i = 0; i < n; i++) { /* Can still cheat? */ - if ((tre_isalnum(fg->wpattern[i])) || tre_isspace(fg->wpattern[i]) || - (fg->wpattern[i] == TRE_CHAR('_')) || (fg->wpattern[i] == TRE_CHAR(',')) || - (fg->wpattern[i] == TRE_CHAR('=')) || (fg->wpattern[i] == TRE_CHAR('-')) || - (fg->wpattern[i] == TRE_CHAR(':')) || (fg->wpattern[i] == TRE_CHAR('/'))) { + if ((tre_isalnum(pat[i])) || tre_isspace(pat[i]) || + (pat[i] == TRE_CHAR('_')) || (pat[i] == TRE_CHAR(',')) || + (pat[i] == TRE_CHAR('=')) || (pat[i] == TRE_CHAR('-')) || + (pat[i] == TRE_CHAR(':')) || (pat[i] == TRE_CHAR('/'))) continue; - } else if (fg->wpattern[i] == TRE_CHAR('.')) + else if (pat[i] == TRE_CHAR('.')) fg->hasdot = i; - else { - /* Free memory and let others know this is empty. */ - free(fg->wpattern); - fg->wpattern = NULL; + else return REG_BADPAT; - } } + /* + * pat has been adjusted earlier to not include '^', '$' or + * the word match character classes at the beginning and ending + * of the string respectively. + */ #ifdef TRE_WCHAR + SAVE_PATTERN(fg->wpattern, fg->wlen); STORE_MBS_PAT; #else - fg->len = fg->wlen; - fg->patter = fg->wpattern; + SAVE_PATTERN(fg->pattern, fg->len); #endif FILL_QSBC;