From nobody Mon Jul 7 04:46:28 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1521528609741766.1677242059693; Mon, 19 Mar 2018 23:50:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3195B81239; Tue, 20 Mar 2018 06:50:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92874425F; Tue, 20 Mar 2018 06:50:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 14559181BA02; Tue, 20 Mar 2018 06:50:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2K6neMQ019459 for ; Tue, 20 Mar 2018 02:49:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4077160BE3; Tue, 20 Mar 2018 06:49:40 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5C765FCA2 for ; Tue, 20 Mar 2018 06:49:39 +0000 (UTC) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 622D54DD49 for ; Tue, 20 Mar 2018 06:49:38 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id t6so1261802wmt.5 for ; Mon, 19 Mar 2018 23:49:38 -0700 (PDT) Received: from rst.Home ([2a02:c7d:692a:c500:1ebc:73f3:5f60:b131]) by smtp.gmail.com with ESMTPSA id g38sm1923269wra.77.2018.03.19.23.49.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Mar 2018 23:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=czUdeq3fSkBf22BfifeYiOz7vk3I//srSEd5ffGawLg=; b=J3BOAapCkPrzl5KOBKm/pGvTFV/RIj1kay4AmaRJqdBbVWLsxfVEoHw306bEiME1ao uxh+xkpnoii2M8zrA6j246C+lU1LH8y8ST7rbW0bx8nAKRg+uKiBdceVeNmwiF7BAEuE 2UQ9MUDsU68PANmiuIlH9iv5LRMPXeSdTU5SceHvmPV0H5KNoDHJIuQy2dPkZmzF0sw4 KkuM4qdOSHkrM8SMVRFqTDNdrH6bIJMj2xHGSBCGjlIOQ1Ahc29x5vv+OnS35/RGTKue 0w7KnUJs9XF6KvawJScxbn3qrsKGwuVQShhMnVaV6D4JXv1Bcc68KzLKSqktTzDf5dTU IYug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=czUdeq3fSkBf22BfifeYiOz7vk3I//srSEd5ffGawLg=; b=lJynO6Y4OdmGUkgFsxnNp4VcZiZSy77xzfDXgQE+XPm//k2Wi3yMauxlaHXFSs9Urf QuYZgn7rFVkYpZhj9hN11XjUFYA2V0ri5hU7QGilGODUirCO1yJgE8seJ04ydVq4R166 jgrcQX3nzTeuI4p+kH2mBFFEI+WaBDccEzJWa5agSojaWxTji38qBv1RXSHZcmiUPGgO 6R0Wxf0LyLn6Q1DQd7u90HrN/L6pK3jg4JtAT0Rw23hS1uRHgLlNrSUwY/ojsRWllXvS DoXYSS5M3KsBYSSDhW9TXwsfjtMyPLpNJtLfZTHGGKRw9Pvi8LwD0t8RbFiktTeqydwM 9nFA== X-Gm-Message-State: AElRT7HWY3hFvoJh+89SRO5iHol9qQca5CIzExTAPuwSVi93pHZGyDz6 VAsb8GmnWVXpwwhTTPGy7OXhABbA X-Google-Smtp-Source: AG47ELtO31bQmmvS6I2ZAfujMoCUuc0JxiNiUDXba0Ed3lrjg65SYZg/562dUhOFqsEGkqnzREUCjA== X-Received: by 10.28.173.8 with SMTP id w8mr1004089wme.18.1521528576701; Mon, 19 Mar 2018 23:49:36 -0700 (PDT) From: Radostin Stoyanov To: libvir-list@redhat.com Date: Tue, 20 Mar 2018 06:48:53 +0000 Message-Id: <20180320064908.17723-11-rstoyanov1@gmail.com> In-Reply-To: <20180320064908.17723-1-rstoyanov1@gmail.com> References: <20180320064908.17723-1-rstoyanov1@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 20 Mar 2018 06:49:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 20 Mar 2018 06:49:38 +0000 (UTC) for IP:'74.125.82.67' DOMAIN:'mail-wm0-f67.google.com' HELO:'mail-wm0-f67.google.com' FROM:'rstoyanov1@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.12 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.67 mail-wm0-f67.google.com 74.125.82.67 mail-wm0-f67.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Radostin Stoyanov Subject: [libvirt] [PATCHv2 10/25] apibuild: Simplify conditional statements X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 20 Mar 2018 06:50:08 +0000 (UTC) X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Improve readability by reducing the complexity and length of conditional statements. Example: The following condition: if (o >=3D 97 and o <=3D 122) or (o >=3D 65 and o <=3D 90) or (o >=3D 48 and o <=3D 57) or (" \t(){}:;,+-*/%&!|[]=3D><".find(line[i]) =3D=3D -1): Will be True for every character that is not in string: " \t(){}:;,+-*/%&!|[]=3D><" Signed-off-by: Radostin Stoyanov --- docs/apibuild.py | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/docs/apibuild.py b/docs/apibuild.py index a11c2d145..51df9dc30 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -386,14 +386,13 @@ class index: def merge_public(self, idx): for id in idx.functions.keys(): if id in self.functions: + up =3D idx.functions[id] # check that function condition agrees with header - if idx.functions[id].conditionals !=3D \ - self.functions[id].conditionals: + if up.conditionals !=3D self.functions[id].conditionals: self.warning("Header condition differs from Function = for %s:" \ % id) self.warning(" H: %s" % self.functions[id].condition= als) - self.warning(" C: %s" % idx.functions[id].conditiona= ls) - up =3D idx.functions[id] + self.warning(" C: %s" % up.conditionals) self.functions[id].update(None, up.module, up.type, up.in= fo, up.extra) # else: # print("Function %s from %s is not declared in headers" = % ( @@ -515,7 +514,7 @@ class CLexer: self.last =3D ('string', tok) return self.last =20 - if l >=3D 2 and line[0] =3D=3D '/' and line[1] =3D=3D '*': + if line.startswith("/*"): line =3D line[2:] found =3D 0 tok =3D "" @@ -539,7 +538,7 @@ class CLexer: return None self.last =3D ('comment', tok) return self.last - if l >=3D 2 and line[0] =3D=3D '/' and line[1] =3D=3D '/': + if line.startswith("//"): line =3D line[2:] self.last =3D ('comment', line) return self.last @@ -564,28 +563,23 @@ class CLexer: if line[i] =3D=3D ' ' or line[i] =3D=3D '\t': i =3D i + 1 continue - o =3D ord(line[i]) - if (o >=3D 97 and o <=3D 122) or (o >=3D 65 and o <=3D 90)= or \ - (o >=3D 48 and o <=3D 57): + if line[i].isalnum(): s =3D i while i < l: - o =3D ord(line[i]) - if (o >=3D 97 and o <=3D 122) or (o >=3D 65 and o = <=3D 90) or \ - (o >=3D 48 and o <=3D 57) or \ - (" \t(){}:;,+-*/%&!|[]=3D><".find(line[i]) =3D= =3D -1): + if line[i] not in " \t(){}:;,+-*/%&!|[]=3D><": i =3D i + 1 else: break self.tokens.append(('name', line[s:i])) continue - if "(){}:;,[]".find(line[i]) !=3D -1: + if line[i] in "(){}:;,[]": # if line[i] =3D=3D '(' or line[i] =3D=3D ')' or line[i] = =3D=3D '{' or \ # line[i] =3D=3D '}' or line[i] =3D=3D ':' or line[i] = =3D=3D ';' or \ # line[i] =3D=3D ',' or line[i] =3D=3D '[' or line[i] = =3D=3D ']': self.tokens.append(('sep', line[i])) i =3D i + 1 continue - if "+-*><=3D/%&!|.".find(line[i]) !=3D -1: + if line[i] in "+-*><=3D/%&!|.": # if line[i] =3D=3D '+' or line[i] =3D=3D '-' or line[i] = =3D=3D '*' or \ # line[i] =3D=3D '>' or line[i] =3D=3D '<' or line[i] = =3D=3D '=3D' or \ # line[i] =3D=3D '/' or line[i] =3D=3D '%' or line[i] = =3D=3D '&' or \ @@ -597,8 +591,7 @@ class CLexer: continue =20 j =3D i + 1 - if j < l and ( - "+-*><=3D/%&!|".find(line[j]) !=3D -1): + if j < l and line[j] in "+-*><=3D/%&!|": # line[j] =3D=3D '+' or line[j] =3D=3D '-' or line[j= ] =3D=3D '*' or \ # line[j] =3D=3D '>' or line[j] =3D=3D '<' or line[j= ] =3D=3D '=3D' or \ # line[j] =3D=3D '/' or line[j] =3D=3D '%' or line[j= ] =3D=3D '&' or \ @@ -611,10 +604,7 @@ class CLexer: continue s =3D i while i < l: - o =3D ord(line[i]) - if (o >=3D 97 and o <=3D 122) or (o >=3D 65 and o <=3D= 90) or \ - (o >=3D 48 and o <=3D 57) or \ - (" \t(){}:;,+-*/%&!|[]=3D><".find(line[i]) =3D=3D -= 1): + if line[i] not in " \t(){}:;,+-*/%&!|[]=3D><": # line[i] !=3D ' ' and line[i] !=3D '\t' and # line[i] !=3D '(' and line[i] !=3D ')' and # line[i] !=3D '{' and line[i] !=3D '}' and @@ -1555,10 +1545,8 @@ class CParser: if token is None: return token =20 - while token[0] =3D=3D "name" and ( - token[1] =3D=3D "const" or \ - token[1] =3D=3D "unsigned" or \ - token[1] =3D=3D "signed"): + while (token[0] =3D=3D "name" and + token[1] in ["const", "unsigned", "signed"]): if self.type =3D=3D "": self.type =3D token[1] else: @@ -2402,8 +2390,7 @@ class docBuilder: pass typ =3D sorted(funcs.keys()) for type in typ: - if type =3D=3D '' or type =3D=3D 'void' or type =3D=3D "int" o= r \ - type =3D=3D "char *" or type =3D=3D "const char *": + if type in ['', "void", "int", "char *", "const char *"]: continue output.write(" \n" % (type)) ids =3D funcs[type] @@ -2431,8 +2418,7 @@ class docBuilder: pass typ =3D sorted(funcs.keys()) for type in typ: - if type =3D=3D '' or type =3D=3D 'void' or type =3D=3D "int" o= r \ - type =3D=3D "char *" or type =3D=3D "const char *": + if type in ['', "void", "int", "char *", "const char *"]: continue output.write(" \n" % (type)) ids =3D sorted(funcs[type]) --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list