From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2752 invoked by alias); 19 Jun 2017 19:35:50 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41321 Received: (qmail 19892 invoked from network); 19 Jun 2017 19:35:50 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-1.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(80.0.253.65):SA:0(-1.0/5.0):. Processed in 5.5205 secs); 19 Jun 2017 19:35:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _smtprelay.virginmedia.com designates 80.0.253.65 as permitted sender) X-Originating-IP: [86.21.219.59] X-Authenticated-User: p.w.stephenson@ntlworld.com X-Spam: 0 X-Authority: v=2.1 cv=NqQsCJpJ c=1 sm=1 tr=0 a=utowdAHh8RITBM/6U1BPxA==:117 a=utowdAHh8RITBM/6U1BPxA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=x7bEGLp0ZPQA:10 a=pGLkceISAAAA:8 a=tnhP3i6iB5XzRdP_lOkA:9 a=CjuIK1q_8ugA:10 a=6kGIvZw6iX1k4Y-7sg4_:22 Date: Mon, 19 Jun 2017 20:28:35 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: Why sourcing a file is not faster than doing a loop with eval, zle -N Message-ID: <20170619202835.7f207185@ntlworld.com> In-Reply-To: <20170619161601.GB9294@chaz.gmail.com> References: <20170619122413.GA9294@chaz.gmail.com> <170619083116.ZM17323__41722.0601499595$1497886320$gmane$org@torch.brasslantern.com> <20170619161601.GB9294@chaz.gmail.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com; s=meg.feb2017; t=1497900515; bh=92RHw2uXq3kOAD5Vd8nTTXE6NSwCPGHuLDO1OFIqJQA=; h=Date:From:To:Subject:In-Reply-To:References; b=N+UqOSNsQNgb9nQtnYu6aRW926VNMEVMM5puOBLao4AVnW44kNHq1hbMPHtl2/h8F aI/Nqx3VelGPVLGAusKEQrc9lJi1tXn5lT4pNJ5251XvgHirgsdB1lMm0twWl2/MnU bjjHrLjBZ3e6UYsFk8L/BLt8o9B4i+TD5GVI8B1tVJun3Ixd/64tBwtk4V7Z/efVaj 1AAt/t+5KQchbZW/ReY3tDcMtun8+ODQVhqPI4NjEx5nivqGx7B1SJOyVvPT43xgjH D4/9KJXpCSO/csJjMQrgvth5rP58lxyMCF1/n72QmoDdYWJyDvscaPstS0CvM4MYVD A73G0CcBQEU3w== On Mon, 19 Jun 2017 17:16:01 +0100 Stephane Chazelas wrote: > That defeats a benefit of stdio saving read() systems calls by > reading in chunk if we end up doing one system call per byte > anyway. Yes, if it's line buffered we should ideally only be unblocking interrupts once around reading the line, which will dominate the timing. How about something like this? As far as I can tell, fgets is designed from the ground up as Gets Done Properly, so if you have it on your system it will work correctly. I can't think of a case where this wouldn't do the right thing --- fgets will read at most one line and if it does we were going to get the big STDIO overhead at that point anyway. pws diff --git a/Src/input.c b/Src/input.c index 92abaec..03d6476 100644 --- a/Src/input.c +++ b/Src/input.c @@ -147,6 +147,53 @@ shingetline(void) for (;;) { winch_unblock(); dont_queue_signals(); +#ifdef HAVE_FGETS + do { + errno = 0; + p = fgets(buf, BUFSIZ, bshin); + } while (!p && errno == EINTR); + winch_block(); + if (!p) { + restore_queue_signals(q); + return NULL; + } + c = 0; + while (*p) { + if (imeta(STOUC(*p++))) + c++; + } + if (p > buf) { + /* p is pointing to '\0' */ + ptrdiff_t nread = p - buf; + queue_signals(); + line = zrealloc(line, ll + c + nread + 1); + if (c) { + char *dest = line + ll; + char *src = buf; + while (src < p) { + if (imeta(STOUC(*src))) { + *dest++ = Meta; + *dest++ = STOUC(*src++) ^ 32; + } else + *dest++ = *src++; + } + *dest++ = '\0'; + } else { + /* copy null */ + memcpy(line + ll, buf, nread + 1); + } + unqueue_signals(); + /* fgets stops at first newline but stores '\0' after */ + if (p[-1] == '\n') { + restore_queue_signals(q); + return line; + } + ll += nread; + } else { + restore_queue_signals(q); + return NULL; + } +#else do { errno = 0; c = fgetc(bshin); @@ -178,6 +225,7 @@ shingetline(void) p = buf; unqueue_signals(); } +#endif } } diff --git a/configure.ac b/configure.ac index 88da89e..2f19a73 100644 --- a/configure.ac +++ b/configure.ac @@ -1325,7 +1325,8 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \ cygwin_conv_path \ nanosleep \ srand_deterministic \ - setutxent getutxent endutxent getutent) + setutxent getutxent endutxent getutent \ + fgets) AC_FUNC_STRCOLL AH_TEMPLATE([REALPATH_ACCEPTS_NULL],