Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ZSH performance regression in 5.8.1.2-test



On Tue, Apr 26, 2022 at 8:16 AM Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> wrote:
>
> We could use some variant of the following as a configure test for safety.

I will be happiest if someone else plugs that in to configure.ac.

Here's the patch again, replacing fstat with lseek.
diff --git a/Src/input.c b/Src/input.c
index c59232681..8e0a24f92 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -217,12 +217,31 @@ shinbufrestore(void)
 static int
 shingetchar(void)
 {
-    int nread;
+    int nread, rsize = isset(SHINSTDIN) ? 1 : SHINBUFSIZE;
 
     if (shinbufptr < shinbufendptr)
 	return STOUC(*shinbufptr++);
-
+    else if (rsize == 1 && lseek(SHIN, 0, SEEK_CUR) == 0)
+	rsize = SHINBUFSIZE;
     shinbufreset();
+    if (rsize > 1) {
+	do {
+	    errno = 0;
+	    nread = read(SHIN, shinbuffer, rsize);
+	} while (nread < 0 && errno == EINTR);
+	if (nread <= 0)
+	    return -1;
+	if (isset(SHINSTDIN) &&
+	    (shinbufendptr = memchr(shinbuffer, '\n', nread))) {
+	    shinbufendptr++;
+	    rsize = (shinbufendptr - shinbuffer);
+	    if (nread > rsize &&
+		lseek(SHIN, -(nread - rsize), SEEK_CUR) < 0)
+		zerr("lseek(%d, %d): %e", SHIN, -(nread - rsize), errno);
+	} else
+	    shinbufendptr = shinbuffer + nread;
+	return STOUC(*shinbufptr++);
+    }
     for (;;) {
        errno = 0;
        nread = read(SHIN, shinbufendptr, 1);


Messages sorted by: Reverse Date, Date, Thread, Author