Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3824235pxy; Mon, 26 Apr 2021 10:34:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwFOaxPBdO+a42VwikipLNHooTCvVyohZoSR3m/kACZiSB/LD//knQ1nGYJ7hlqWo14A9z X-Received: by 2002:a17:906:3989:: with SMTP id h9mr19462418eje.309.1619458493848; Mon, 26 Apr 2021 10:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619458493; cv=none; d=google.com; s=arc-20160816; b=ER5usgP6WPkrrtKzIFbu3dGhX+GfRwSiGGsBd3if80EfxLVazqr+P7DtroO9w1KLUp HuBDPufWn26fIdIHYzBf+IQViShwhjYAo7/J9tScFVslxuBPIJ+K6/aZ5OE/kvYWTQyD iyUylO1/cZG6b9a0806AkpITVRhCPV/JojbYEJEIcx1/fgGb2fD2DFdAwCDcO/TZs4tT iWPyGueuv/24GJEjW/XuguWoPfyhe9GAg3VyOY3Ny1TM1KYaNAyFoDCdycSJKhdxWvhF Qke1/Ub3FQvWaHCbKN2WKCsBzyPzCNzCV3zOH+3zzmxqj2KFgTm/wElEmY+hHTNituh7 DCHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sEsgnbR9Bd5/MELEwxLgHOD1YuAgY9Prs8WjOgXrw04=; b=Irb65BjFPepGj0omcylcib33vP78XZdLftJEPE+7N73NS/YdF2S3rrKlMzW32UhWg6 LEfN5UhiHjh/W67NqTI76uAHJoKyopIClQBUEEpfBljnegq9MyRNsDwIy1vweFAZ9AeM wn3XeMIBrTF9KrJonEK5PGhEB/WNiwAst65QO5DiGX3nHvQKCh+/dizwWT1WjkLxSq1a 4Y7N9wwlh8WU4W7p5zxlJk+22u3Dbe1+j6cWIE/54T75AQM+LRmeTi7kJ1FKKn/NPpnI JdAep/7m3taj9Xx92FuNk8pAVSBmypMCDdGR2yCXnHbOckVvuXgTEUPhIy9qfp3wrxaX kcHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=jWxiyEf1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c17si346914edw.358.2021.04.26.10.34.28; Mon, 26 Apr 2021 10:34:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=jWxiyEf1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236349AbhDZRb7 (ORCPT + 99 others); Mon, 26 Apr 2021 13:31:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236264AbhDZRb7 (ORCPT ); Mon, 26 Apr 2021 13:31:59 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FAD0C061574; Mon, 26 Apr 2021 10:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=sEsgnbR9Bd5/MELEwxLgHOD1YuAgY9Prs8WjOgXrw04=; b=jWxiyEf1/h7v6v/zUTVDudlE8c Sl5uCsPzX/1NTkE16ziM651qe8yFaVQbZrI7f6eKKvLoVA3E556OPEbCuCbWdfJUXvhgU4DPxol62 +QvztcslRjRM5965YaU5y8SojB5Kz0t9KJQyRBrxhd+MB40G+o60vRg9gxtSz96g/CcFItiMfVsF4 G24MGWDozUhuBA37bsu9p2b8z077z5JdnZuYMtyK4w6/E7/rpeRSsnl0V9mYhXZhkRE67D42a3dfW +n0p2DySZx5Zmwncc8eu72X0T4FXF+sNZbl4i3zmT3HkBCl05qku4X7MtJvjIEcbUqemvsCfdg/U5 iCukrDtg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lb54Y-005uHt-Bm; Mon, 26 Apr 2021 17:31:04 +0000 Date: Mon, 26 Apr 2021 18:31:02 +0100 From: Matthew Wilcox To: Aditya Srivastava Cc: corbet@lwn.net, lukas.bulwahn@gmail.com, linux-kernel-mentees@lists.linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC] scripts: kernel-doc: reduce repeated regex expressions into variables Message-ID: <20210426173102.GO235567@casper.infradead.org> References: <20210422191839.6119-1-yashsri421@gmail.com> <20210423132117.GB235567@casper.infradead.org> <6f76ddcb-7076-4c91-9c4c-995002c4cb91@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6f76ddcb-7076-4c91-9c4c-995002c4cb91@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 24, 2021 at 05:27:34PM +0530, Aditya Srivastava wrote: > On 23/4/21 6:51 pm, Matthew Wilcox wrote: > > On Fri, Apr 23, 2021 at 12:48:39AM +0530, Aditya Srivastava wrote: > >> +my $pointer_function = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)}; > > > > Is that a pointer-to-function? Or as people who write C usually call it, > > a function pointer? Wouldn't it be better to call it $function_pointer? > > > Will do it. > > >> @@ -1210,8 +1211,14 @@ sub dump_struct($$) { > >> my $decl_type; > >> my $members; > >> my $type = qr{struct|union}; > >> + my $packed = qr{__packed}; > >> + my $aligned = qr{__aligned}; > >> + my $cacheline_aligned_in_smp = qr{____cacheline_aligned_in_smp}; > >> + my $cacheline_aligned = qr{____cacheline_aligned}; > > > > I don't think those four definitions actually simplify anything. > > > >> + my $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i; > > > > ... whereas this one definitely does. > > > >> - $members =~ s/\s*__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)/ /gi; > >> - $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; > >> - $members =~ s/\s*__packed\s*/ /gos; > >> + $members =~ s/\s*$attribute/ /gi; > >> + $members =~ s/\s*$aligned\s*\([^;]*\)/ /gos; > > > > Maybe put the \s*\([^;]*\) into $aligned? Then it becomes a useful > > abstraction. > > Actually, I had made these variables as they were repeated here and at > - my $definition_body = > qr{\{(.*)\}(?:\s*(?:__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*}; > + my $definition_body = > qr{\{(.*)\}(?:\s*(?:$packed|$aligned|$cacheline_aligned_in_smp|$cacheline_aligned|$attribute))*}; > > So, defining them at a place might help. > > What do you think? I don't think that seeing $packed is any easier to read than __packed. Indeed, I think it's harder, because now I have to look up what $packed is defined as. Defining a variable, say $decorations = qr{__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\))} (i didn't count brackets to be sure i got that right) would be helpful because then we could say: my $definition_body = qr{\{(.*)\}...$decorations... and have a fighting chance of understanding what it means. Now, this other place we use it, we do the =~ operation a number of times. Is there a way to use the $decorations variable to do the same thing with a single operation?