From bd6f8b834caaa426f00dfd5f164d2434201ace71 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 2 Mar 2010 20:10:40 +0000 Subject: [PATCH] * Slightly more computationally efficient version of memfmout() that doesn't use cprintf() and doesn't switch into kernel space one character at a time. --- citadel/msgbase.c | 25 ++++++++++++++++++------- citadel/sysdep.c | 2 ++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/citadel/msgbase.c b/citadel/msgbase.c index d189c77e3..40635193a 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -931,12 +931,18 @@ void memfmout( ) { int column = 0; char ch = 0; - if (!mptr) return; + char outbuf[1024]; + int len = 0; + int nllen = 0; + if (!mptr) return; + nllen = strlen(nl); while (ch=*(mptr++), ch > 0) { if (ch == '\n') { - cprintf("%s", nl); + client_write(outbuf, len); + len = 0; + client_write(nl, nllen); column = 0; } else if (ch == '\r') { @@ -944,20 +950,25 @@ void memfmout( } else if (isspace(ch)) { if (column > 72) { /* Beyond 72 columns, break on the next space */ - cprintf("%s", nl); + client_write(outbuf, len); + len = 0; + client_write(nl, nllen); column = 0; } else { - cprintf("%c", ch); + outbuf[len++] = ch; + ++column; } } else { + outbuf[len++] = ch; + ++column; if (column > 1000) { /* Beyond 1000 columns, break anywhere */ - cprintf("%s", nl); + client_write(outbuf, len); + len = 0; + client_write(nl, nllen); column = 0; } - cprintf("%c", ch); - ++column; } } } diff --git a/citadel/sysdep.c b/citadel/sysdep.c index d748de23a..ce584837b 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -461,6 +461,8 @@ int client_write(const char *buf, int nbytes) CitContext *Ctx; int fdflags; + if (nbytes < 1) return(0); + // flush_client_inbuf(); Ctx = CC; if (Ctx->redirect_buffer != NULL) { -- 2.39.2