Skip to content

Commit 1a7cf97

Browse files
more efficient DataFrame::nrows, i.e. one that does not have to pay the price for R special case handling of R_RowNamesSymbol
1 parent 373a8b4 commit 1a7cf97

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

inst/include/Rcpp/DataFrame.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ namespace Rcpp{
6161
}
6262

6363
inline int nrows() const {
64-
SEXP rn = Rf_getAttrib( Parent::get__(), R_RowNamesSymbol );
65-
if (TYPEOF(rn) == INTSXP && LENGTH(rn) == 2 && INTEGER(rn)[0] == NA_INTEGER)
66-
return INTEGER(rn)[1];
64+
SEXP rn = R_NilValue ;
65+
SEXP att = ATTRIB( Parent::get__() ) ;
66+
while( att != R_NilValue ){
67+
if( TAG(att) == R_RowNamesSymbol ) {
68+
rn = CAR(att) ;
69+
break ;
70+
}
71+
att = CDR(att) ;
72+
}
6773
if (Rf_isNull(rn))
6874
return 0;
75+
if (TYPEOF(rn) == INTSXP && LENGTH(rn) == 2 && INTEGER(rn)[0] == NA_INTEGER)
76+
return -INTEGER(rn)[1];
6977
return LENGTH(rn);
7078
}
7179

0 commit comments

Comments
 (0)