From nobody Sat Jul 5 15:54:11 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 1521296738826319.92108446329166; Sat, 17 Mar 2018 07:25:38 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 982DC369BD; Sat, 17 Mar 2018 14:25:37 +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 7105A76133; Sat, 17 Mar 2018 14:25:37 +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 359C2181B9FF; Sat, 17 Mar 2018 14:25:37 +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 w2HENxrg000573 for ; Sat, 17 Mar 2018 10:23:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id B832680E81; Sat, 17 Mar 2018 14:23:59 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B179F77D48 for ; Sat, 17 Mar 2018 14:23:59 +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 895BE8553D for ; Sat, 17 Mar 2018 14:23:58 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id 139so7948615wmn.2 for ; Sat, 17 Mar 2018 07:23:58 -0700 (PDT) Received: from rst.Home ([2a02:c7d:692a:c500:1ebc:73f3:5f60:b131]) by smtp.gmail.com with ESMTPSA id i66sm11060550wmd.0.2018.03.17.07.23.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 17 Mar 2018 07:23:56 -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=Jh3O4appKj66LTBY0YWUftThqzDB8TeI7kvUIQH3mGs=; b=f2qT39P8UF6qXqFUz7BjYtSl8sFhYh2RPpvbEhqwTy22alO2yWwAYvz0gnIy3C93fJ CBZuLO6IeQuBt76MBUX/nzhR22/uPrjyczLVR2D5AZe7DI3YIDuamDvb7MwFGL7y7xoW IR/FMnc/V/ThYIIs0/aZFtrSa7Ac+jvSizxLTJrH02gG7ky6aIZGqidqPHNGirakIf+k NeofKwgd/mM0kEv2Hv7mNJDNWzoFtXLNdDpU4eImClywXwKorvbW43ZgenblvmsAteL9 XwNq483mXifCYx/+oygOo2Q4/LSxs35hQ/Nadunba1bZQ9YNj94yG2gcNSEywg17iU5c VAdg== 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=Jh3O4appKj66LTBY0YWUftThqzDB8TeI7kvUIQH3mGs=; b=VyavP9ATGx5fOb4Qu9Gj78FiQxc5GwI9WvPup3bm7P3Nfc38WMjne2yStcwV7Q9x6Q vcHp7POE492kcR9suWA85swhu3LdHWjEDcROcBKyZM4+kWzpRVIj2m6T9XQC030izezA aqbfLHf1gYayiOn6ehKus9Mxim32GaN+huaVRXNs+uIkENA/Lx8PVR9GWcdRrawBu7VB AyXvmf9NIOdPVzOC7ACQguIn0vmdXrKtz4L299yQ3RrSms6IQ257YgCgtbqwAMJt5Q2+ 97QWTtGq11HDIF9PdTU/3n7yQVpaOGQ5KuZSiU5taRsaD28TzXmh/dFPOIr8VbnfnquT tuEw== X-Gm-Message-State: AElRT7H5VGuK9Gp847HXfmIiv1jHZvXOmBkQK4x+DpEgoFxK5Hxcarph hfKtCm+husd5W1z0FRqHy7AR8Dag X-Google-Smtp-Source: AG47ELuhvW7IOO01yXzioievXpy4ujC/VxLiMBjAzeAeiNho2uqfTyfbgj0NZXjF3j85sfjxKkC2+g== X-Received: by 10.28.52.9 with SMTP id b9mr4739307wma.134.1521296636894; Sat, 17 Mar 2018 07:23:56 -0700 (PDT) From: Radostin Stoyanov To: libvir-list@redhat.com Date: Sat, 17 Mar 2018 14:23:27 +0000 Message-Id: <20180317142340.11653-10-rstoyanov1@gmail.com> In-Reply-To: <20180317142340.11653-1-rstoyanov1@gmail.com> References: <20180317142340.11653-1-rstoyanov1@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 17 Mar 2018 14:23:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 17 Mar 2018 14:23:58 +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.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Radostin Stoyanov Subject: [libvirt] [PATCH 09/22] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 17 Mar 2018 14:25:38 +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 | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/docs/apibuild.py b/docs/apibuild.py index 644d96f69..1b9401226 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -564,28 +564,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 re.match(r"[a-zA-Z0-9]", line[i]): 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 +592,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 +605,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 +1546,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 +2391,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 +2419,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