88*/
99SEXP between (SEXP x , SEXP lower , SEXP upper , SEXP incbounds , SEXP NAboundsArg , SEXP checkArg ) {
1010 int nprotect = 0 ;
11- R_len_t nx = length (x ), nl = length (lower ), nu = length (upper );
11+ const R_len_t nx = length (x ), nl = length (lower ), nu = length (upper );
1212 if (!nx || !nl || !nu )
1313 return (allocVector (LGLSXP , 0 ));
1414 const int longest = MAX (MAX (nx , nl ), nu );
@@ -20,13 +20,13 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S
2020 const int longestBound = MAX (nl , nu ); // just for when check=TRUE
2121 if (!IS_TRUE_OR_FALSE (incbounds ))
2222 error (_ ("%s must be TRUE or FALSE" ), "incbounds" );
23- const bool open = !LOGICAL (incbounds )[0 ];
24- if (!isLogical (NAboundsArg ) || LOGICAL (NAboundsArg )[0 ]== FALSE)
23+ const bool open = !LOGICAL_RO (incbounds )[0 ];
24+ if (!isLogical (NAboundsArg ) || LOGICAL_RO (NAboundsArg )[0 ]== FALSE)
2525 error (_ ("NAbounds must be TRUE or NA" ));
26- const bool NAbounds = LOGICAL (NAboundsArg )[0 ]== TRUE;
26+ const bool NAbounds = LOGICAL_RO (NAboundsArg )[0 ]== TRUE;
2727 if (!IS_TRUE_OR_FALSE (checkArg ))
2828 error (_ ("%s must be TRUE or FALSE" ), "check" );
29- const bool check = LOGICAL (checkArg )[0 ];
29+ const bool check = LOGICAL_RO (checkArg )[0 ];
3030 const bool verbose = GetVerbose ();
3131
3232 // check before potential coercion which ignores methods, #7164
@@ -70,13 +70,13 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S
7070 const int uppMask = recycleUpp ? 0 : INT_MAX ;
7171 SEXP ans = PROTECT (allocVector (LGLSXP , longest )); nprotect ++ ;
7272 int * restrict ansp = LOGICAL (ans );
73- double tic = omp_get_wtime ();
73+ const double tic = omp_get_wtime ();
7474
7575 switch (TYPEOF (x )) {
7676 case INTSXP : {
77- const int * lp = INTEGER (lower );
78- const int * up = INTEGER (upper );
79- const int * xp = INTEGER (x );
77+ const int * lp = INTEGER_RO (lower );
78+ const int * up = INTEGER_RO (upper );
79+ const int * xp = INTEGER_RO (x );
8080 if (check ) for (int i = 0 ; i < longestBound ; ++ i ) {
8181 const int l = lp [i & lowMask ], u = up [i & uppMask ];
8282 if (l != NA_INTEGER && u != NA_INTEGER && l > u )
@@ -103,9 +103,9 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S
103103
104104 case REALSXP :
105105 if (INHERITS (x , char_integer64 )) {
106- const int64_t * lp = (int64_t * ) REAL (lower );
107- const int64_t * up = (int64_t * ) REAL (upper );
108- const int64_t * xp = (int64_t * ) REAL (x );
106+ const int64_t * lp = (const int64_t * ) REAL_RO (lower );
107+ const int64_t * up = (const int64_t * ) REAL_RO (upper );
108+ const int64_t * xp = (const int64_t * ) REAL_RO (x );
109109 if (check ) for (int i = 0 ; i < longestBound ; ++ i ) {
110110 const int64_t l = lp [i & lowMask ], u = up [i & uppMask ];
111111 if (l != NA_INTEGER64 && u != NA_INTEGER64 && l > u )
@@ -128,9 +128,9 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S
128128 }
129129 if (verbose ) Rprintf (_ ("between parallel processing of integer64 took %8.3fs\n" ), omp_get_wtime ()- tic );
130130 } else {
131- const double * lp = REAL (lower );
132- const double * up = REAL (upper );
133- const double * xp = REAL (x );
131+ const double * lp = REAL_RO (lower );
132+ const double * up = REAL_RO (upper );
133+ const double * xp = REAL_RO (x );
134134 if (check ) for (int i = 0 ; i < longestBound ; ++ i ) {
135135 const double l = lp [i & lowMask ], u = up [i & uppMask ];
136136 if (!isnan (l ) && !isnan (u ) && l > u )
0 commit comments