From patchwork Tue Apr 6 17:46:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1462940 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=I+6sHzps; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FFFM91xjKz9s1l for ; Wed, 7 Apr 2021 03:46:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8DD613857823; Tue, 6 Apr 2021 17:46:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DD613857823 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1617731186; bh=jBfQZfQXZeucWWShP3A5O/MRDNburpHmxnlBZp0uyNA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=I+6sHzpseWoRDPl7OBrpEKLK6M6jHRU8rytpHc0pH7RcY3GWazX6CqngdbiJ/a4IQ Ozl5AQQa1gIW6gMtefYnWQerGgt/lvsRcxnkrieH2CToUc5I+BsMUCUm36L7r8V+oQ pcv4OIh7i/iRXFS8NtEzPrPOBjh2FY0Q2qIdQjxk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050::465:101]) by sourceware.org (Postfix) with ESMTPS id 264B53857823 for ; Tue, 6 Apr 2021 17:46:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 264B53857823 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4FFFM309KszQjfH; Tue, 6 Apr 2021 19:46:23 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id LE28CyZx2_Fo; Tue, 6 Apr 2021 19:46:19 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Use Array::find to get index of element Date: Tue, 6 Apr 2021 19:46:18 +0200 Message-Id: <20210406174618.1594147-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: ** X-Rspamd-Score: 1.67 / 15.00 / 15.00 X-Rspamd-Queue-Id: D96E017CC X-Rspamd-UID: d003a6 X-Spam-Status: No, score=-15.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch refactors some code in the code generator to use the Array::find method to get the index of an element, instead of looping over the array ourselves. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32 and committed to mainline. Regards, Iain. --- gcc/d/ChangeLog: * d-codegen.cc (build_frame_type): Use Array::find to get index of element. --- gcc/d/d-codegen.cc | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 608abcd94f5..5fa1acd9240 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -2507,15 +2507,11 @@ build_frame_type (tree ffi, FuncDeclaration *fd) { VarDeclaration *v = (*fd->parameters)[i]; /* Remove if already in closureVars so can push to front. */ - for (size_t j = i; j < fd->closureVars.length; j++) - { - Dsymbol *s = fd->closureVars[j]; - if (s == v) - { - fd->closureVars.remove (j); - break; - } - } + size_t j = fd->closureVars.find (v); + + if (j < fd->closureVars.length) + fd->closureVars.remove (j); + fd->closureVars.insert (i, v); } } @@ -2523,15 +2519,11 @@ build_frame_type (tree ffi, FuncDeclaration *fd) /* Also add hidden `this' to outer context. */ if (fd->vthis) { - for (size_t i = 0; i < fd->closureVars.length; i++) - { - Dsymbol *s = fd->closureVars[i]; - if (s == fd->vthis) - { - fd->closureVars.remove (i); - break; - } - } + size_t i = fd->closureVars.find (fd->vthis); + + if (i < fd->closureVars.length) + fd->closureVars.remove (i); + fd->closureVars.insert (0, fd->vthis); } }