diff mbox

[Ada] Move variable-length components to last position in record types

Message ID 20170502085517.GA135063@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet May 2, 2017, 8:55 a.m. UTC
This optimizes the layout of some record types declared in the runtime, but
only in the private part of the spec or in the body, hence no API changes.

There is also a similar to the Xr_Tabls support package.

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

2017-05-02  Eric Botcazou  <ebotcazou@adacore.com>

	* g-forstr.ads (Data): Move Format component last.
	* g-forstr.adb ("+"): Adjust for above change.
	* g-rewdat.ads (Buffer): Move Buffer, Current, Pattern and Value last.
	* g-sechas.ads (Context): Move Key last.
	* g-socket.ads (Service_Entry_Type): Move Aliases last.
	* s-fileio.adb (Temp_File_Record): Move Name last.
	* s-regexp.adb (Regexp_Value): Move Case_Sensitive last.
	* xr_tabls.ads (Project_File): Move Src_Dir and Obj_Dir last.
diff mbox

Patch

Index: xr_tabls.ads
===================================================================
--- xr_tabls.ads	(revision 247461)
+++ xr_tabls.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1998-2014, Free Software Foundation, Inc.         --
+--          Copyright (C) 1998-2017, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -292,12 +292,11 @@ 
 
 private
    type Project_File (Src_Dir_Length, Obj_Dir_Length : Natural) is record
-      Src_Dir : String (1 .. Src_Dir_Length);
-      Src_Dir_Index : Integer;
-
-      Obj_Dir            : String (1 .. Obj_Dir_Length);
+      Src_Dir_Index      : Integer;
       Obj_Dir_Index      : Integer;
       Last_Obj_Dir_Start : Natural;
+      Src_Dir            : String (1 .. Src_Dir_Length);
+      Obj_Dir            : String (1 .. Obj_Dir_Length);
    end record;
 
    type Project_File_Ptr is access all Project_File;
@@ -364,7 +363,6 @@ 
 
    type Declaration_Record (Symbol_Length : Natural) is record
       Key          : Cst_String_Access;
-      Symbol       : String (1 .. Symbol_Length);
       Decl         : Reference;
       Is_Parameter : Boolean := False; -- True if entity is subprog param
       Decl_Type    : Character;
@@ -374,6 +372,7 @@ 
       Match        : Boolean := False;
       Par_Symbol   : Declaration_Reference := null;
       Next         : Declaration_Reference := null;
+      Symbol       : String (1 .. Symbol_Length);
    end record;
    --  The lists of referenced (Body_Ref, Ref_Ref and Modif_Ref) are
    --  kept unsorted until the results needs to be printed. This saves
Index: g-sechas.ads
===================================================================
--- g-sechas.ads	(revision 247461)
+++ g-sechas.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2009-2016, Free Software Foundation, Inc.         --
+--          Copyright (C) 2009-2017, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -208,14 +208,14 @@ 
       --  KL is 0 for a normal hash context, > 0 for HMAC
 
       type Context (KL : Key_Length := 0) is record
-         Key : Stream_Element_Array (1 .. KL);
-         --  HMAC key
-
          H_State : Hash_State.State (0 .. State_Words - 1) := Initial_State;
          --  Function-specific state
 
          M_State : Message_State (Block_Length);
          --  Function-independent state (block buffer)
+
+         Key : Stream_Element_Array (1 .. KL);
+         --  HMAC key
       end record;
 
       Initial_Context : constant Context (KL => 0) := (others => <>);
Index: g-rewdat.ads
===================================================================
--- g-rewdat.ads	(revision 247461)
+++ g-rewdat.ads	(working copy)
@@ -5,7 +5,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---            Copyright (C) 2014, Free Software Foundation, Inc.            --
+--           Copyright (C) 2014-2017, Free Software Foundation, Inc.        --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -128,6 +128,12 @@ 
    type Buffer
      (Size, Size_Pattern, Size_Value : Stream_Element_Offset) is
    limited record
+      Pos_C : Stream_Element_Offset; -- last valid element in Current
+      Pos_B : Stream_Element_Offset; -- last valid element in Buffer
+
+      Next  : Buffer_Ref;
+      --  A link to another rewriter if any
+
       Buffer : Stream_Element_Array (1 .. Size);
       --  Fully prepared/rewritten data waiting to be output
 
@@ -141,12 +147,6 @@ 
 
       Value : Stream_Element_Array (1 .. Size_Value);
       --  The value the pattern is replaced by
-
-      Pos_C : Stream_Element_Offset; -- last valid element in Current
-      Pos_B : Stream_Element_Offset; -- last valid element in Buffer
-
-      Next  : Buffer_Ref;
-      --  A link to another rewriter if any
    end record;
 
 end GNAT.Rewrite_Data;
Index: s-regexp.adb
===================================================================
--- s-regexp.adb	(revision 247461)
+++ s-regexp.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---                     Copyright (C) 1999-2016, AdaCore                     --
+--                     Copyright (C) 1999-2017, AdaCore                     --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -68,9 +68,9 @@ 
       Num_States    : State_Index) is
    record
       Map            : Mapping;
+      Case_Sensitive : Boolean;
       States         : Regexp_Array (1 .. Num_States, 0 .. Alphabet_Size);
       Is_Final       : Boolean_Array (1 .. Num_States);
-      Case_Sensitive : Boolean;
    end record;
    --  Deterministic finite-state machine
 
Index: g-socket.ads
===================================================================
--- g-socket.ads	(revision 247461)
+++ g-socket.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---                     Copyright (C) 2001-2016, AdaCore                     --
+--                     Copyright (C) 2001-2017, AdaCore                     --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -1268,9 +1268,9 @@ 
 
    type Service_Entry_Type (Aliases_Length : Natural) is record
       Official : Name_Type;
-      Aliases  : Name_Array (1 .. Aliases_Length);
       Port     : Port_Type;
       Protocol : Name_Type;
+      Aliases  : Name_Array (1 .. Aliases_Length);
    end record;
 
    type Request_Flag_Type is mod 2 ** 8;
Index: g-forstr.adb
===================================================================
--- g-forstr.adb	(revision 247461)
+++ g-forstr.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2014-2016, Free Software Foundation, Inc.         --
+--          Copyright (C) 2014-2017, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -130,8 +130,8 @@ 
    begin
       return Formatted_String'
         (Finalization.Controlled with
-           D => new Data'(Format'Length, 1, Format, 1,
-             Null_Unbounded_String, 0, 0, (0, 0)));
+           D => new Data'(Format'Length, 1, 1,
+             Null_Unbounded_String, 0, 0, (0, 0), Format));
    end "+";
 
    ---------
Index: g-forstr.ads
===================================================================
--- g-forstr.ads	(revision 247461)
+++ g-forstr.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---           Copyright (C) 2014-2016, Free Software Foundation, Inc.        --
+--           Copyright (C) 2014-2017, Free Software Foundation, Inc.        --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -287,12 +287,12 @@ 
 
    type Data (Size : Natural) is record
       Ref_Count    : Natural := 1;
-      Format       : String (1 .. Size); -- the format string
       Index        : Positive := 1;      -- format index for next value
       Result       : Unbounded_String;   -- current value
       Current      : Natural;            -- the current format number
       Stored_Value : Natural := 0;       -- number of stored values in Stack
       Stack        : I_Vars;
+      Format       : String (1 .. Size); -- the format string
    end record;
 
    type Data_Access is access Data;
Index: s-fileio.adb
===================================================================
--- s-fileio.adb	(revision 247465)
+++ s-fileio.adb	(working copy)
@@ -63,8 +63,8 @@ 
 
    type Temp_File_Record is record
       File : AFCB_Ptr;
+      Next : aliased Temp_File_Record_Ptr;
       Name : String (1 .. max_path_len + 1);
-      Next : aliased Temp_File_Record_Ptr;
    end record;
    --  One of these is allocated for each temporary file created