Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use read only pointer for atomic vectors in R_compute_identical() #170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/identical.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,19 @@ R_compute_identical(SEXP x, SEXP y, int flags)
case LGLSXP:
if (XLENGTH(x) != XLENGTH(y)) return FALSE;
/* Use memcmp (which is ISO C90) to speed up the comparison */
return memcmp((void *)LOGICAL(x), (void *)LOGICAL(y),
return memcmp((const void *)LOGICAL_RO(x), (const void *)LOGICAL_RO(y),
xlength(x) * sizeof(int)) == 0 ? TRUE : FALSE;
case INTSXP:
if (XLENGTH(x) != XLENGTH(y)) return FALSE;
/* Use memcmp (which is ISO C90) to speed up the comparison */
return memcmp((void *)INTEGER(x), (void *)INTEGER(y),
return memcmp((const void *)INTEGER_RO(x), (const void *)INTEGER_RO(y),
xlength(x) * sizeof(int)) == 0 ? TRUE : FALSE;
case REALSXP:
{
R_xlen_t n = XLENGTH(x);
if(n != XLENGTH(y)) return FALSE;
else {
double *xp = REAL(x), *yp = REAL(y);
const double *xp = REAL_RO(x), *yp = REAL_RO(y);
int ne_strict = NUM_EQ | (SINGLE_NA << 1);
for(R_xlen_t i = 0; i < n; i++)
if(neWithNaN(xp[i], yp[i], ne_strict)) return FALSE;
Expand All @@ -254,7 +254,7 @@ R_compute_identical(SEXP x, SEXP y, int flags)
R_xlen_t n = XLENGTH(x);
if(n != XLENGTH(y)) return FALSE;
else {
Rcomplex *xp = COMPLEX(x), *yp = COMPLEX(y);
const Rcomplex *xp = COMPLEX_RO(x), *yp = COMPLEX_RO(y);
int ne_strict = NUM_EQ | (SINGLE_NA << 1);
for(R_xlen_t i = 0; i < n; i++)
if(neWithNaN(xp[i].r, yp[i].r, ne_strict) ||
Expand Down Expand Up @@ -345,7 +345,7 @@ R_compute_identical(SEXP x, SEXP y, int flags)
case RAWSXP:
if (XLENGTH(x) != XLENGTH(y)) return FALSE;
/* Use memcmp (which is ISO C90) to speed up the comparison */
return memcmp((void *)RAW(x), (void *)RAW(y),
return memcmp((const void *)RAW_RO(x), (const void *)RAW_RO(y),
XLENGTH(x) * sizeof(Rbyte)) == 0 ? TRUE : FALSE;
case PROMSXP:
{
Expand Down
Loading