From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71916 invoked by alias); 31 May 2018 08:56:51 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 71898 invoked by uid 89); 31 May 2018 08:56:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy=plenty X-HELO: mail-yb0-f172.google.com Received: from mail-yb0-f172.google.com (HELO mail-yb0-f172.google.com) (209.85.213.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 31 May 2018 08:56:49 +0000 Received: by mail-yb0-f172.google.com with SMTP id p22-v6so7325117yba.13 for ; Thu, 31 May 2018 01:56:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=n3exsQ/oxC7NrJtVyIkezd2CqnOWs7RD7/Fhq199nKU=; b=PfIqX1fOdBpyVdbwrsXqZVk8wLG4L5reUo6tSBENaN8xYhr3jL56xPohGzgx8Elj9P W3uPE0rHldXbxzPlfFB/O/KShXtqC/yn3SmeOLhDWXquMtiSHhfqFgy+E7PmOdENWXT/ V+zuuJ6kTRWSioZuShjjcL+Umd705dqe0O7IEOSNwDLVukGt8Gw6Mpa0Osj9EDefWHIK EMKqAPOvyhPxaJzU0fvBhGrJs/s23Ujq51Al2dskhueNy6eN/biA2ReswTml8BHCNatn kMC7zRjHjNPWoaGzQBCdK4Er20/SBU789IZgk1xnApNNO5+YiAEqJn0aa7vvqv8EYs1Q xhCw== X-Gm-Message-State: ALKqPweOEChPmyx5VxlRA7gIwWmdAjh9MBvNq2RaOXbpMRCXAc43sB8l uYOlVLr7f4CoBvAzzaw4CMH2Eaoe2DbYeOvh21k= X-Google-Smtp-Source: ADUXVKLWLhjYvKQSORqJhSDmQaDJoyoCXojTTxx4KlO2MGdNImQtz2r6q5DN15obN0PNWHfnh3YbrPA09JHicZ7njmw= X-Received: by 2002:a25:b301:: with SMTP id l1-v6mr3430176ybj.184.1527757008063; Thu, 31 May 2018 01:56:48 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a81:6f08:0:0:0:0:0 with HTTP; Thu, 31 May 2018 01:56:47 -0700 (PDT) In-Reply-To: <2073064.y6ql7gNeXd@andrew-precision-3520> References: <6944935.KTWIneVxun@andrew-precision-3520> <2946507.05iJNWrpSJ@andrew-precision-3520> <2073064.y6ql7gNeXd@andrew-precision-3520> From: Janus Weil Date: Thu, 31 May 2018 08:56:00 -0000 Message-ID: Subject: Re: Optimization of add_dt_to_dt_list() in resolve.c To: Andrew Benson Cc: Richard Biener , "fortran@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2018-05/txt/msg00139.txt.bz2 2018-05-31 0:22 GMT+02:00 Andrew Benson : >> - for (dt = gfc_derived_types; dt; dt = dt->next) >> - gfc_copy_dt_decls_ifequal (derived, dt->derived, false); >> - >> + if (gfc_derived_types) { >> + dt = gfc_derived_types; >> + for (;;) >> + { >> + gfc_copy_dt_decls_ifequal (derived, dt, false); >> + if (dt->dt_next == gfc_derived_types) >> + break; >> + dt = dt->dt_next; >> + } >> + } >> >> Is there a particular reason why you changed the loop to "for (;;)" ? >> I find the old style a bit clearer and more compact. Also I think it's >> more common in gfortran. > > I changed the original for loop since it wasn't possible (as far as I could > see) to have an exit condition that worked now that list is circularly linked > (i.e. "dt" never becomes NULL, and testing for dt->dt_next == > gfc_derived_types doesn't work as it would miss the final entry in the list). > So, I used for(;;) and added the exit condition explicitly into the loop. > > But, I agree, it's not very clear. An alternative would be something such as: > > - for (dt = gfc_derived_types; dt; dt = dt->next) > - gfc_copy_dt_decls_ifequal (derived, dt->derived, false); > - > + for (dt = gfc_derived_types; dt; dt = dt->dt_next) > + { > + gfc_copy_dt_decls_ifequal (derived, dt, false); > + if (dt->dt_next == gfc_derived_types) > + break; > + } > + > > which is more compact, and has the advantage that if doesn't require an "if > (gfc_derived_types)". Do you think that's a better approach? Yes, definitely looks better to me. Note that there is another such case further up in gfc_get_derived_type. Actually I'd also move the declaration of dt ("gfc_symbol *dt") into the loops, in order to make it more local (it's not used outside). Btw, another thing that you'll need is a ChangeLog entry that lists every file and function touched by your patch and gives a short description of the modifications. You'll find plenty of examples for this in gcc/fortran/ChangeLog. Cheers, Janus