From patchwork Mon May 18 08:07:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 473294 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48DB11402B5 for ; Mon, 18 May 2015 18:07:30 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=ZJoQkVhE; dkim-atps=neutral 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:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=Tb7GE/D2mczkbmMJe dCUohXVoqUz/kXCPJdjlvMofAmzMx6iftMpOAV5mSqvTi0Ap1sCxcT2lZvWyyEjk Y7fGYRsO8vMyzSBrcRwZgTmDrXoYtxiImvo4sGvTMW+ZdiVLOr4UPyJDN/JhSYox 0VUzkUMfDPvh9HO7PRXzVSnTE8= 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:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=n3kehmfRPzOthZ2Ws+sl1/a xZgo=; b=ZJoQkVhEutAQdry4cK/AsgQiIkjt0LQZr+Nvxqz3bCKS8cv5mcRkBv2 oK5dPLfcnftJgfTpoP67YXCj+HacDoClrdJpy9ZixaYKBOjjezGeOTMREGJWZtZY ixf33jEm9wYeN8OXRVBDV0JAIEQTSignfo9QSjJGgOOaFVyJ58Bw= Received: (qmail 18916 invoked by alias); 18 May 2015 08:07:20 -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 18901 invoked by uid 89); 18 May 2015 08:07:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 18 May 2015 08:07:18 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1YuG4v-0005j3-ML from Tom_deVries@mentor.com ; Mon, 18 May 2015 01:07:14 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Mon, 18 May 2015 09:07:12 +0100 Message-ID: <55599DAD.6030800@mentor.com> Date: Mon, 18 May 2015 10:07:09 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Jeff Law , GCC Patches Subject: Re: [PATCH, 5/5] check_GNU_style.sh: Fix tab size in 80 characters check References: <5551ABF1.7040908@mentor.com> <55521935.7050501@redhat.com> In-Reply-To: <55521935.7050501@redhat.com> On 12-05-15 17:16, Jeff Law wrote: >> [PATCH 5/5] check_GNU_style.sh: Fix tab size in 80 characters check >> >> 2015-05-11 Tom de Vries >> >> * check_GNU_style.sh (col): Fix tab size. > OK. Hi Jeff, I. I noticed a performance degradation due to this patch: ... $ cat gcc/tree-ssa-tail-merge.c | awk '{printf "+%s\n", $0}' | time -p ./contrib/check_GNU_style.sh - ... real 4.10 user 0.71 sys 6.77 ... Before this patch, the 'real' time was roughly a factor 80 smaller: ... real 0.05 user 0.02 sys 0.03 ... This degradation is due to the fact that the patch does the 80 chars check line-by-line, and invokes processes for each new line. II. Attached follow-up patch rewrites the 80 chars check to handle a file at a time rather than a line at a time, and gets performance back to normal: ... real 0.07 user 0.03 sys 0.05 ... As a bonus, the bit longer than 80 chars is now printed in red, similar to how the other checks show the output. OK for trunk? Thanks, - Tom check_GNU_style.sh: Don't do 80 char check line by line 2015-05-18 Tom de Vries * check_GNU_style.sh: Add temp files tmp2 and tmp3. (cat_with_prefix): New function, using global variable prefix. (col): Make prefix a global variable. Rewrite to process file at a time rather than line at a time. Print part longer than 80 chars in red. --- contrib/check_GNU_style.sh | 70 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/contrib/check_GNU_style.sh b/contrib/check_GNU_style.sh index ab59b1e..033a2c9 100755 --- a/contrib/check_GNU_style.sh +++ b/contrib/check_GNU_style.sh @@ -65,10 +65,12 @@ fi inp=check_GNU_style.inp tmp=check_GNU_style.tmp +tmp2=check_GNU_style.2.tmp +tmp3=check_GNU_style.3.tmp # Remove $tmp on exit and various signals. -trap "rm -f $inp $tmp $stdin_tmp" 0 -trap "rm -f $inp $tmp $stdin_tmp; exit 1" 1 2 3 5 9 13 15 +trap "rm -f $inp $tmp $tmp2 $tmp3 $stdin_tmp" 0 +trap "rm -f $inp $tmp $tmp2 $tmp3 $stdin_tmp; exit 1" 1 2 3 5 9 13 15 if [ $nfiles -eq 1 ]; then # There's no need for the file prefix if we're dealing only with one file. @@ -80,6 +82,17 @@ grep $format '^+' $files \ | grep -v ':+++' \ > $inp +cat_with_prefix () +{ + local f="$1" + + if [ "$prefix" = "" ]; then + cat "$f" + else + awk "{printf "%s%s\n", $prefix, \$0}" $f + fi +} + # Grep g (){ local msg="$1" @@ -134,10 +147,11 @@ vg (){ col (){ local msg="$1" + local first=true local f for f in $files; do - local prefix="" + prefix="" if [ $nfiles -ne 1 ]; then prefix="$f:" fi @@ -148,22 +162,42 @@ col (){ | grep -v ':+++' \ > $tmp - cat $tmp | while IFS= read -r line; do - local longline - # Filter out the line number prefix and the patch line modifier '+' - # to obtain the bare line, before we use expand. - longline=$(echo "$line" \ - | sed 's/^[0-9]*:+//' \ - | expand \ - | awk '{ if (length($0) > 80) print $0}') - if [ "$longline" != "" ]; then - if $first; then - printf "\n$msg\n" - first=false - fi - echo "$prefix$line" + # Keep only line number prefix and patch modifier '+'. + cat "$tmp" \ + | sed 's/\(^[0-9][0-9]*:+\).*/\1/' \ + > "$tmp2" + + # Remove line number prefix and patch modifier '+'. + # Expand tabs to spaces according to tab positions. + # Keep long lines, make short lines empty. Print the part past 80 chars + # in red. + cat "$tmp" \ + | sed 's/^[0-9]*:+//' \ + | expand \ + | awk '{ \ + if (length($0) > 80) \ + printf "%s\033[1;31m%s\033[0m\n", \ + substr($0,1,80), \ + substr($0,81); \ + else \ + print "" \ + }' \ + > "$tmp3" + + # Combine prefix back with long lines. + # Filter out empty lines. + local found=false + paste -d '' "$tmp2" "$tmp3" \ + | grep -v '^[0-9][0-9]*:+$' \ + > "$tmp" && found=true + + if $found; then + if $first; then + printf "\n$msg\n" + first=false fi - done + cat_with_prefix "$tmp" + fi done } -- 1.9.1