From patchwork Mon Oct 26 22:34:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 536338 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2C53E141333 for ; Tue, 27 Oct 2015 09:37:54 +1100 (AEDT) Received: from localhost ([::1]:55571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqqOl-0007lS-R9 for incoming@patchwork.ozlabs.org; Mon, 26 Oct 2015 18:37:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqqMB-0003Gj-NN for qemu-devel@nongnu.org; Mon, 26 Oct 2015 18:35:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqqM6-0006vg-Qc for qemu-devel@nongnu.org; Mon, 26 Oct 2015 18:35:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44608) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqqM6-0006vG-Ll for qemu-devel@nongnu.org; Mon, 26 Oct 2015 18:35:06 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 6604F8F2FE; Mon, 26 Oct 2015 22:35:06 +0000 (UTC) Received: from red.redhat.com (ovpn-113-189.phx2.redhat.com [10.3.113.189]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9QMZ4Da006171; Mon, 26 Oct 2015 18:35:06 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 26 Oct 2015 16:34:41 -0600 Message-Id: <1445898903-12082-3-git-send-email-eblake@redhat.com> In-Reply-To: <1445898903-12082-1-git-send-email-eblake@redhat.com> References: <1445898903-12082-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v11 02/24] qapi: More idiomatic string operations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Rather than slicing the end of a string, we can use python's endswith(). And rather than creating a set of characters, we can search for a character within a string. Signed-off-by: Eric Blake --- v11: no change v10: new patch --- scripts/qapi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 9d53255..3af4c2c 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -172,7 +172,7 @@ class QAPISchemaParser(object): if self.tok == '#': self.cursor = self.src.find('\n', self.cursor) - elif self.tok in ['{', '}', ':', ',', '[', ']']: + elif self.tok in "{}:,[]": return elif self.tok == "'": string = '' @@ -390,7 +390,7 @@ def add_name(name, info, meta, implicit=False): raise QAPIExprError(info, "%s '%s' is already defined" % (all_names[name], name)) - if not implicit and name[-4:] == 'Kind': + if not implicit and name.endswith('Kind'): raise QAPIExprError(info, "%s '%s' should not end in 'Kind'" % (meta, name)) @@ -910,7 +910,7 @@ class QAPISchemaEnumType(QAPISchemaType): def is_implicit(self): # See QAPISchema._make_implicit_enum_type() - return self.name[-4:] == 'Kind' + return self.name.endswith('Kind') def c_type(self, is_param=False): return c_name(self.name)