Skip to content

Commit

Permalink
use R_xlen_t in loops
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Apr 29, 2024
1 parent 9fc394e commit 8ba89f5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/altrep-sparse-real.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ static SEXP altrep_sparse_real_Extract_subset(SEXP x, SEXP indx, SEXP call) {
SEXP data1 = R_altrep_data1(x);
SEXP val_old = VECTOR_ELT(data1, 0);
SEXP pos_old = VECTOR_ELT(data1, 1);

SEXP matches = PROTECT(Rf_match(pos_old, indx, R_NaInt));
R_xlen_t n_matches = Rf_xlength(matches);

int n = 0;

for (int i = 0; i < Rf_length(matches); ++i) {
for (R_xlen_t i = 0; i < n_matches; ++i) {
if (INTEGER_ELT(matches, i) != R_NaInt) {
n++;
}
Expand All @@ -82,13 +84,13 @@ static SEXP altrep_sparse_real_Extract_subset(SEXP x, SEXP indx, SEXP call) {
int step = 0;
int what_pos = 1;

for (int i = 0; i < Rf_length(matches); ++i) {
for (R_xlen_t i = 0; i < n_matches; ++i) {

int match = INTEGER_ELT(matches, i);
if (match != R_NaInt) {
SET_REAL_ELT(val_new, step, REAL_ELT(val_old, match - 1));

for (int j = 0; j < Rf_length(matches); ++j) {
for (R_xlen_t j = 0; j < n_matches; ++j) {
if (INTEGER_ELT(indx, j) == INTEGER_ELT(pos_old, match - 1)) {
break;
} else {
Expand Down Expand Up @@ -151,7 +153,7 @@ static double altrep_sparse_real_Elt(SEXP x, R_xlen_t i) {

double out = 0;

for (int j = 0; j < n; ++j) {
for (R_xlen_t j = 0; j < n; ++j) {
if (INTEGER_ELT(pos, j) == i + 1) {
out = REAL_ELT(val, j);
break;
Expand Down

0 comments on commit 8ba89f5

Please sign in to comment.