From 21af0bf02de5c9664d05c5f49d26a6817ce9ba06 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sun, 10 Nov 2024 00:09:20 -0800 Subject: [PATCH] Import upstream bestline changes --- llamafile/bestline.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/llamafile/bestline.c b/llamafile/bestline.c index 56e2b3004a..b5509066a6 100644 --- a/llamafile/bestline.c +++ b/llamafile/bestline.c @@ -2029,6 +2029,10 @@ static ssize_t bestlineCompleteLine(struct bestlineState *ls, char *seq, int siz ls->len = saved.len; ls->pos = saved.pos; ls->buf = saved.buf; + if (lc.len == 1) { + nread = 0; + goto FinishQuickly; + } } else { bestlineRefreshLine(ls); } @@ -2045,6 +2049,7 @@ static ssize_t bestlineCompleteLine(struct bestlineState *ls, char *seq, int siz break; default: if (i < lc.len) { + FinishQuickly: n = strlen(lc.cvec[i]); if (bestlineGrow(ls, n + 1)) { memcpy(ls->buf, lc.cvec[i], n + 1);