Skip to content
Prev 62979 / 63421 Next

table() and as.character() performance for logical values

On 4/11/25 16:23, Suharto Anggono Suharto Anggono via R-devel wrote:
If this is the caching you had in mind:

 ??? > attribute_hidden SEXP StringFromLogical(int x, int *warn)
 ??? > {
 ??? >??? static SEXP TrueCh, FalseCh;
 ??? >??? if (x == NA_LOGICAL) return NA_STRING;
 ??? >??? else if (x) return TrueCh ? TrueCh : (TrueCh = mkChar("TRUE"));
 ??? >??? else return FalseCh ? FalseCh : (FalseCh = mkChar("FALSE"));

that is really a protection error. StringFromLogical() should make sure 
that TrueCh, FalseCh will be protected as long as recorded in the static 
field. PreserveObject() would be a natural function for this.

Best
Tomas