public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-230] [Ada] Avoid repeated conversions from Int to Char_Code
@ 2022-05-10  8:21 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-10  8:21 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:53f2aaf0b3c322e65d014ad2203a706bc8b26b8f

commit r13-230-g53f2aaf0b3c322e65d014ad2203a706bc8b26b8f
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Tue Jan 18 21:24:32 2022 +0100

    [Ada] Avoid repeated conversions from Int to Char_Code
    
    When expanding aggregates like "(others => 'x')" into strings we
    repeated conversion from Int to Char_Code for every character.  Now we
    convert once and use the Char_Code directly.
    
    Cleanup related to handling characters in GNATprove counterexamples;
    semantics is unaffected.
    
    gcc/ada/
    
            * exp_aggr.adb (Expand_N_Aggregate): Replace UI_To_Int with
            UI_To_CC; replace magic literals with high-level routines that
            recognise wide and wide wide characters; reorder if-then-elsif
            condition, because we don't have a routine to detect wide wide
            characters.

Diff:
---
 gcc/ada/exp_aggr.adb | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 9e781e01d03..939d091e065 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -7161,10 +7161,10 @@ package body Exp_Aggr is
                  and then No (Expressions (N))
                then
                   declare
-                     X  : constant Node_Id := First_Index (T);
-                     EC : constant Node_Id := Expression (CA);
-                     CV : constant Uint    := Char_Literal_Value (EC);
-                     CC : constant Int     := UI_To_Int (CV);
+                     X  : constant Node_Id   := First_Index (T);
+                     EC : constant Node_Id   := Expression (CA);
+                     CV : constant Uint      := Char_Literal_Value (EC);
+                     CC : constant Char_Code := UI_To_CC (CV);
 
                   begin
                      if Nkind (X) = N_Range
@@ -7180,17 +7180,19 @@ package body Exp_Aggr is
                               Start_String;
 
                               for J in 1 .. UI_To_Int (Hi) loop
-                                 Store_String_Char (Char_Code (CC));
+                                 Store_String_Char (CC);
                               end loop;
 
                               Rewrite (N,
                                 Make_String_Literal (Sloc (N),
                                   Strval => End_String));
 
-                              if CC >= Int (2 ** 16) then
-                                 Set_Has_Wide_Wide_Character (N);
-                              elsif CC >= Int (2 ** 8) then
+                              if In_Character_Range (CC) then
+                                 null;
+                              elsif In_Wide_Character_Range (CC) then
                                  Set_Has_Wide_Character (N);
+                              else
+                                 Set_Has_Wide_Wide_Character (N);
                               end if;
 
                               Analyze_And_Resolve (N, T);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-10  8:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10  8:21 [gcc r13-230] [Ada] Avoid repeated conversions from Int to Char_Code Pierre-Marie de Rodat

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).