Attached is a suggested patch for src/main/character.c.  It does not fix
a bug, but rather provides an improvement on the recent extension of
do_grep.

In essence, instead of four occurences of 'invert ^ LOGICAL(ind)[i]'
that accommodate for the option 'invert' added to grep, there is one
occurence of 'LOGICAL(ind)[i] ^= invert' that modifies in-place the
logical vector of matched/unmatched flags.  Having the inversion done in
just one place instead of four locations in the code should make it
simpler to understand, maintain, and further extend the code.

The patch was made based on the src/main/character.c file in
R-devel_2009-01-20.  Patched code was successfully compiled and tested
on 32bit Ubuntu 8.04.

Regards,
Wacek


-- 
-------------------------------------------------------------------------------
Wacek Kusnierczyk, MD PhD

Email: w...@idi.ntnu.no
Phone: +47 73591875, +47 72574609

Department of Computer and Information Science (IDI)
Faculty of Information Technology, Mathematics and Electrical Engineering (IME)
Norwegian University of Science and Technology (NTNU)
Sem Saelands vei 7, 7491 Trondheim, Norway
Room itv303

Bioinformatics & Gene Regulation Group
Department of Cancer Research and Molecular Medicine (IKM)
Faculty of Medicine (DMF)
Norwegian University of Science and Technology (NTNU)
Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway
Room 231.05.060

-------------------------------------------------------------------------------

1018c1018
<     int igcase_opt, extended_opt, value_opt, perl_opt, fixed_opt, useBytes, invert;
---
>     int igcase_opt, extended_opt, value_opt, perl_opt, fixed_opt, useBytes, invert, logical_opt;
1034c1034,1035
<     invert = asLogical(CAR(args));
---
>     invert = asLogical(CAR(args)); args = CDR(args);
>     logical_opt = asLogical(CAR(args));
1041a1043
>     if (logical_opt == NA_INTEGER) logical_opt = 0;
1051a1054,1057
>     if (value_opt && logical_opt) {
>         warning(_("argument '%s' will be ignored"), "logical = TRUE");
>         logical_opt = 0;
>     }
1151c1157,1158
< 	if (invert ^ LOGICAL(ind)[i]) nmatches++;
---
>    LOGICAL(ind)[i] ^= invert;
> 	if (LOGICAL(ind)[i]) nmatches++;
1165c1172
< 	    if (invert ^ LOGICAL(ind)[i])
---
> 	    if (LOGICAL(ind)[i])
1171c1178
< 		if (invert ^ LOGICAL(ind)[i])
---
> 		if (LOGICAL(ind)[i])
1175c1182,1184
<     } else {
---
>     } else if (logical_opt) {
>         return ind;
>     } else{
1179c1188
< 	    if (invert ^ LOGICAL(ind)[i]) INTEGER(ans)[j++] = i + 1;
---
> 	    if (LOGICAL(ind)[i]) INTEGER(ans)[j++] = i + 1;
2843c2852
<     
---
> 
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to