From patchwork Thu Nov 7 14:37:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 289371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 39E822C00C3 for ; Fri, 8 Nov 2013 01:37:41 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:from:to:cc:subject:date:in-reply-to:references :content-type:content-transfer-encoding:mime-version; q=dns; s= default; b=rohofDrTcT/pcExbtrPqYW/TqSIkNfDFP3G4LNmxbqSaQHVbi9RZd JS9zrIBSH6a+0j6Ot2ZatuIKJ4r/jg7oiPghzpvWkB4HT3qIkFqdheidQFFphyAF X1a8SvlrYYuXqy3Z2tg19T/ffop7QOapM7lpEDD+ZfmEjxgU5h+VfA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:from:to:cc:subject:date:in-reply-to:references :content-type:content-transfer-encoding:mime-version; s=default; bh=yxKA75LbGQquToPQAirizmxk0u4=; b=H4QeDX1x+IpnKrACFgoBR720cj6U D4whFLYcDFUeR+II/cvXE5m8IPmcelBUqjSf4CbfDlevEpaRHvuZlYfjMo3b+3Dc xs8RbpyLBdZ6Rxq07n7xvAh2KJCayVhb/Q7vKqHwFfmbu0kNhOZWfVufpXf3rOED Tcz0q1e3JKBQ+zE= Received: (qmail 1193 invoked by alias); 7 Nov 2013 14:37:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 1182 invoked by uid 89); 7 Nov 2013 14:37:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.5 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RDNS_NONE, SPAM_SUBJECT, SPF_PASS autolearn=no version=3.3.2 X-HELO: dub0-omc4-s34.dub0.hotmail.com Received: from Unknown (HELO dub0-omc4-s34.dub0.hotmail.com) (157.55.2.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Nov 2013 14:37:28 +0000 Received: from DUB122-W26 ([157.55.2.71]) by dub0-omc4-s34.dub0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 7 Nov 2013 06:37:20 -0800 X-TMN: [+UIaohZXKuJApXW6xSiujFyxB6Lbex+L] Message-ID: From: Bernd Edlinger To: Jakub Jelinek CC: Dodji Seketeli , Nathan Sidwell , =?iso-8859-1?B?TWFudWVsIEzzcGV6LUli4fFleg==?= , GCC Patches Subject: RE: [PATCH] Factorize the two read_line functions present in gcov.c and input.c Date: Thu, 7 Nov 2013 15:37:20 +0100 In-Reply-To: <20131107124814.GZ27813@tucnak.zalov.cz> References: <87bo1xfcjl.fsf@redhat.com>, <527B3E7F.3000305@acm.org>, <87bo1weew6.fsf@redhat.com>, , <20131107124814.GZ27813@tucnak.zalov.cz> MIME-Version: 1.0 On Thu, 7 Nov 2013 13:48:14, Jakub Jelinek wrote: > On Thu, Nov 07, 2013 at 01:25:00PM +0100, Bernd Edlinger wrote: >> just some thoughts... >> >> >> fgetc will definitely be much faster than fread 16K and fseek back to the end of line position. >> >> Note: fgetc is already buffered and not too slow on average, but only if you do not >> fseek around. In that case the buffered file-stream data is lost. > > fgetc (unless you are talking about fgetc_unlocked which is somewhat better) > is actually very expensive. Of course, fseek is highly undersirable, but > I've already said that. > > Jakub yes. That's true. I think, maybe this patch tries just to reach too many goals at the same time. What is the _real_ bug which should be fixed first, is that even a very short file with NUL-chars goes OOM in read_line. So stay with fgets, just detect that the file is binary and return in that case. The performance and duplicate code can still be improved by a follow-up patch. We do not really need any caret positions on a binary file, after all, we just should not ICE. Maybe that could be done by just detecting that we have a BINARY file, and stop printing any further lines. like this? Bernd. --- input.c.jj    2013-01-10 21:38:27.000000000 +0100 +++ input.c    2013-11-07 15:33:53.804990865 +0100 @@ -106,12 +106,15 @@ read_line (FILE *file)      {        size_t len = strlen (string + pos);   -      if (string[pos + len - 1] == '\n') +      if (len && string[pos + len - 1] == '\n')      {        string[pos + len - 1] = 0;        return string;      }        pos += len; +      /* test if binary file or last line incomplete? */ +      if (pos < string_len-1) +    return pos && feof (file) ? string : NULL;        string = XRESIZEVEC (char, string, string_len * 2);        string_len *= 2;      }