From 2f72845c78f59fe1ae8398e4fcb0369e2d0d475c Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Mon, 29 Apr 2024 11:44:56 -0700 Subject: [PATCH] pull out len neatly --- src/altrep-sparse-real.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/altrep-sparse-real.c b/src/altrep-sparse-real.c index 2ff6f4a..3d55ab7 100644 --- a/src/altrep-sparse-real.c +++ b/src/altrep-sparse-real.c @@ -137,14 +137,15 @@ Rboolean altrep_sparse_real_Inspect(SEXP x, // ALTREAL static double altrep_sparse_real_Elt(SEXP x, R_xlen_t i) { - - if (i > Rf_asReal(VECTOR_ELT(R_altrep_data1(x), 2))) { - return NA_REAL; - } - SEXP data1 = R_altrep_data1(x); SEXP val = VECTOR_ELT(data1, 0); SEXP pos = VECTOR_ELT(data1, 1); + SEXP len = VECTOR_ELT(data1, 2); + R_xlen_t c_len = (R_xlen_t) INTEGER_ELT(len, 0); + + if (i > c_len) { + return NA_REAL; + } const R_xlen_t n = Rf_xlength(val);