View | Details | Raw Unified | Return to bug 17132
Collapse All | Expand All

(-)src/main/grep.c (-5 / +7 lines)
Lines 982-990 Link Here
982
static R_size_t fgrepraw1(SEXP pat, SEXP text, R_size_t offset) {
982
static R_size_t fgrepraw1(SEXP pat, SEXP text, R_size_t offset) {
983
    Rbyte *haystack = RAW(text), *needle = RAW(pat);
983
    Rbyte *haystack = RAW(text), *needle = RAW(pat);
984
    R_size_t n = LENGTH(text);
984
    R_size_t n = LENGTH(text);
985
    switch (LENGTH(pat)) { /* it may be silly but we optimize small needle
985
    R_size_t ncmp = LENGTH(pat);
986
			      searches, because they can be used to match
986
    if (n < ncmp)
987
			      single UTF8 chars (up to 3 bytes) */
987
	return (R_size_t) -1;
988
    switch (ncmp) { /* it may be silly but we optimize small needle
989
		       searches, because they can be used to match
990
		       single UTF8 chars (up to 3 bytes) */
988
    case 1:
991
    case 1:
989
	{
992
	{
990
	    Rbyte c = needle[0];
993
	    Rbyte c = needle[0];
Lines 1019-1027 Link Here
1019
	}
1022
	}
1020
    default:
1023
    default:
1021
	{
1024
	{
1022
	    R_size_t ncmp = LENGTH(pat);
1025
	    ncmp--;
1023
	    n -= ncmp;
1026
	    n -= ncmp;
1024
	    ncmp--;
1025
	    while (offset < n) {
1027
	    while (offset < n) {
1026
		if (haystack[offset] == needle[0] &&
1028
		if (haystack[offset] == needle[0] &&
1027
		    !memcmp(haystack + offset + 1, needle + 1, ncmp))
1029
		    !memcmp(haystack + offset + 1, needle + 1, ncmp))

Return to bug 17132