From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [Ada] Remove redundant checks for empty lists
Date: Wed, 5 May 2021 04:20:05 -0400 [thread overview]
Message-ID: <20210505082005.GA31367@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 605 bytes --]
When iterating over list elements with First/Next there is no need to
detect empty or non-existing list, because First intentionally returns
Empty in those cases.
Cleanup of code related to Unchecked_Unions; behaviour is unaffected.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_ch4.adb (Variant_Is_Unconstrained_UU): Remove redundant
check for empty list.
* exp_disp.adb (Find_Entry_Index): Simplify by removing
redundant check and counting from zero; fix type of a local
variable.
* sem_ch12.adb (Save_Global_Descendant): Remove an unnecessary
special-case for empty lists.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 3404 bytes --]
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -8170,26 +8170,18 @@ package body Exp_Ch4 is
(Variant : Node_Id) return Boolean
is
Clist : constant Node_Id := Component_List (Variant);
+ Comp : Node_Id := First (Component_Items (Clist));
begin
- if Is_Empty_List (Component_Items (Clist)) then
- return False;
- end if;
-
-- We only need to test one component
- declare
- Comp : Node_Id := First (Component_Items (Clist));
-
- begin
- while Present (Comp) loop
- if Component_Is_Unconstrained_UU (Comp) then
- return True;
- end if;
+ while Present (Comp) loop
+ if Component_Is_Unconstrained_UU (Comp) then
+ return True;
+ end if;
- Next (Comp);
- end loop;
- end;
+ Next (Comp);
+ end loop;
-- None of the components withing the variant were of
-- unconstrained Unchecked_Union type.
diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -6640,28 +6640,25 @@ package body Exp_Disp is
----------------------
function Find_Entry_Index (E : Entity_Id) return Uint is
- Index : Uint := Uint_1;
- Subp_Decl : Entity_Id;
+ Index : Uint := Uint_0;
+ Subp_Decl : Node_Id;
begin
- if Present (Decls)
- and then not Is_Empty_List (Decls)
- then
- Subp_Decl := First (Decls);
- while Present (Subp_Decl) loop
- if Nkind (Subp_Decl) = N_Entry_Declaration then
- if Defining_Identifier (Subp_Decl) = E then
- return Index;
- end if;
+ Subp_Decl := First (Decls);
+ while Present (Subp_Decl) loop
+ if Nkind (Subp_Decl) = N_Entry_Declaration then
+ Index := Index + 1;
- Index := Index + 1;
+ if Defining_Identifier (Subp_Decl) = E then
+ exit;
end if;
- Next (Subp_Decl);
- end loop;
- end if;
+ end if;
+
+ Next (Subp_Decl);
+ end loop;
- return Uint_0;
+ return Index;
end Find_Entry_Index;
-- Local variables
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -16169,16 +16169,11 @@ package body Sem_Ch12 is
pragma Assert (D /= Union_Id (No_List));
-- Because No_List = Empty, which is in Node_Range above
- if Is_Empty_List (List_Id (D)) then
- null;
-
- else
- N1 := First (List_Id (D));
- while Present (N1) loop
- Save_References (N1);
- Next (N1);
- end loop;
- end if;
+ N1 := First (List_Id (D));
+ while Present (N1) loop
+ Save_References (N1);
+ Next (N1);
+ end loop;
-- Element list or other non-node field, nothing to do
reply other threads:[~2021-05-05 8:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210505082005.GA31367@adacore.com \
--to=derodat@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=trojanek@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).