Skip to content

Commit 588e6ba

Browse files
author
maechler
committed
speedup StringFromLogical(); by Suharto Anggono
git-svn-id: https://svn.r-project.org/R/trunk@88134 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent cc33aeb commit 588e6ba

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main/coerce.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,14 @@ attribute_hidden Rcomplex ComplexFromString(SEXP x, int *warn)
295295
return z;
296296
}
297297

298+
298299
attribute_hidden SEXP StringFromLogical(int x, int *warn)
299300
{
300-
int w;
301-
formatLogical(&x, 1, &w);
301+
static SEXP TrueCh = NULL, FalseCh = NULL; /* constants, initialized when first used */
302302
if (x == NA_LOGICAL) return NA_STRING;
303-
else return mkChar(EncodeLogical(x, w));
303+
else if (x)
304+
return TrueCh != NULL ? TrueCh : (TrueCh = mkChar("TRUE"));
305+
else return FalseCh!= NULL ? FalseCh : (FalseCh = mkChar("FALSE"));
304306
}
305307

306308
/* The conversions for small non-negative integers are saved in a chache. */

0 commit comments

Comments
 (0)