Skip to content

Commit

Permalink
Performance optimization in gregexpr() from Toby Hocking.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@76138 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
kalibera committed Feb 20, 2019
1 parent fc7aa58 commit 98d2476
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/grep.c
Expand Up @@ -2385,6 +2385,7 @@ gregexpr_perl(const char *pattern, const char *string,
SEXP capturebuf, capturelenbuf;
SEXP matchbuf, matchlenbuf; /* buffers for storing multiple matches */
int bufsize = 1024; /* starting size for buffers */
int slen = (int) strlen(string);
PROTECT_INDEX cb, clb, mb, mlb;

PROTECT_WITH_INDEX(capturebuf =
Expand All @@ -2393,9 +2394,9 @@ gregexpr_perl(const char *pattern, const char *string,
allocVector(INTSXP, bufsize*capture_count), &clb);
PROTECT_WITH_INDEX(matchbuf = allocVector(INTSXP, bufsize), &mb);
PROTECT_WITH_INDEX(matchlenbuf = allocVector(INTSXP, bufsize), &mlb);

while (!foundAll) {
int rc, slen = (int) strlen(string);
rc = pcre_exec(re_pcre, re_pe, string, slen, start, 0, ovector,
int rc = pcre_exec(re_pcre, re_pe, string, slen, start, 0, ovector,
ovector_size);
pcre_exec_error(rc, n);
if (rc >= 0) {
Expand Down

0 comments on commit 98d2476

Please sign in to comment.