Skip to content

Commit cc33aeb

Browse files
author
maechler
committed
add fast path to EncodeLogical(), thanking Suharto Anggono
git-svn-id: https://svn.r-project.org/R/trunk@88133 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 0671d08 commit cc33aeb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/printutils.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ R_size_t R_Decode2Long(char *p, int *ierr)
124124
#define NB 1000
125125
const char *EncodeLogical(int x, int w)
126126
{
127+
/* fast path when 'w' fits exactly */
128+
if(x == NA_LOGICAL) {
129+
if(w == R_print.na_width) return CHAR(R_print.na_string);
130+
} else if(x) {
131+
if(w == 4) return "TRUE";
132+
} else
133+
if(w == 5) return "FALSE";
134+
/* general case */
127135
static char buff[NB];
128136
if(x == NA_LOGICAL) snprintf(buff, NB, "%*s", min(w, (NB-1)), CHAR(R_print.na_string));
129137
else if(x) snprintf(buff, NB, "%*s", min(w, (NB-1)), "TRUE");

0 commit comments

Comments
 (0)