diff mbox

[Ada] Avoid silly long compilation for Wide_Wide_Character'Width

Message ID 20101008123107.GA12436@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 8, 2010, 12:31 p.m. UTC
This patch avoids silly long compilation times for uses of the (silly)
attributes Wide_Wide_Character'Width and Wide_Wide_Character'Image.
The following program should compile instantly with -gnat05 (it used
to take many seconds on a fast machine).

with Ada.Text_IO;
use  Ada.Text_IO;
procedure SlowImage is
begin
   Put_Line (Wide_Wide_Character'Image
             (Wide_Wide_Character'Val (16#0003#)));
   Put_Line (Integer'Image (Wide_Wide_Character'Width));
end;

The output is

ETX
 12

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-10-08  Robert Dewar  <dewar@adacore.com>

	* sem_attr.adb (Eval_Attribute, case Width): Avoid ludicrous long loop
	for case of Wide_[Wide_]Character.
diff mbox

Patch

Index: sem_attr.adb
===================================================================
--- sem_attr.adb	(revision 165082)
+++ sem_attr.adb	(working copy)
@@ -7410,7 +7410,11 @@  package body Sem_Attr is
                         --  All wide characters look like Hex_hhhhhhhh
 
                         if J > 255 then
-                           W := 12;
+
+                           --  No need to compute this more than once!
+
+                           W := Int'Max (W, 12);
+                           exit;
 
                         else
                            C := Character'Val (J);