From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 09A603836029 for ; Tue, 10 May 2022 08:21:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 09A603836029 Received: by mail-wm1-x332.google.com with SMTP id bd25-20020a05600c1f1900b0039485220e16so1002409wmb.0 for ; Tue, 10 May 2022 01:20:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=LUJfOqrKqGVdUBdDkj1sVTowWIVDVmj3KTF4g/EC+6Y=; b=OT76I+ml0hlR7QcClcPgaFpiTMjOLHB9cs97E11wF68/gDJuD4EUo5HGB6Ea/ENTmA c1P39w9h9Wr2eri9SqGa8kcd1F5T3a+eoL78XZmDeJDFnAZhdnItJkivwzH5d/+NVewy XPdANgdqJJeI+Lg/jvbseEBI5JHkA2zRss8kBHEnsuJTclk650AXv1vheBDuKYdDL65D 82y7sNwsGpO0xChx/rZXKcENXAbaZOkDPo0tdCcBozPBbE0SdbSNYji93Pdlga4Nmq21 qQ93iBRmYUxKF/HdH6L+uDsRCBijBYPAN9g5tyv4sPVPTVH/vc7vlMDTqBrIlZsVYOQ2 mgrA== X-Gm-Message-State: AOAM532ud3FnZNtwRUjJOa+H5wgasHXBmll/EotjmeHZ9nJnbsePsgD7 lEcpD+ZuXgrBsSe9E+if2VEWm+FkF2FC1Q== X-Google-Smtp-Source: ABdhPJwdfCE8eMNmB36WesU1zBJU1tFWBt2987ox0sr63zfp3qnjpVFlY6a4uvvKl4IxXUk/gG1kEw== X-Received: by 2002:a1c:3587:0:b0:381:50ff:cbd with SMTP id c129-20020a1c3587000000b0038150ff0cbdmr26916503wma.140.1652170858577; Tue, 10 May 2022 01:20:58 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id p6-20020a05600c358600b0039429bfebeasm5989150wmq.2.2022.05.10.01.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 01:20:58 -0700 (PDT) Date: Tue, 10 May 2022 08:20:57 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Avoid repeated conversions from Int to Char_Code Message-ID: <20220510082057.GA3029034@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="IJpNTDwzlM2Ie8A6" Content-Disposition: inline X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Tue, 10 May 2022 08:21:01 -0000 --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. Tested on x86_64-pc-linux-gnu, committed on trunk 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. --IJpNTDwzlM2Ie8A6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb --- 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); --IJpNTDwzlM2Ie8A6--