[Ada] Improve memory usage in functions Get_Line
Laurent GUERBY
laurent@guerby.net
Wed Mar 26 10:26:00 GMT 2008
On Wed, 2008-03-26 at 09:05 +0100, Arnaud Charlet wrote:
> Tested on i686-linux, committed on trunk
>
> Small improvement, no change of functionality.
>
> 2008-03-26 Vincent Celier <celier@adacore.com>
>
> * a-szuzti.adb, a-swuwti.adb, a-suteio.adb (functions Get_Line):
> Improve memory usage to avoid use of stack.
- Str2 := new Wide_String'(Str1.all & Buffer (1 .. Last));
+ Str2 := new Wide_String (1 .. Str1'Last + Last);
+ Str2 (Str1'Range) := Str1.all;
+ Str2 (Str1'Last + 1 .. Str2'Last) := Buffer (1 .. Last);
Interesting transformation. I wonder if semantically the compiler
can do the stack space optimization in a generic way:
U := V1 (F1 .. L1) & V2 (F2 .. L2) & ...
=>
compute F1 and L1, check constraint against V1
compute F2 and L2, check constraint against V2
...
Compute N1 = L1 - F1 + 1
Compute N2 = L2 - F2 + 1
...
Compute N = N1 + N2 + ...
Create U (1 .. N) or check constraint against U if it is constrained
U (1 .. N1) := V1 (F1 .. L1)
U (N1 + 1 .. N2) := V2 (F2 .. L2)
...
Is there always full semantic equivalence between the two versions?
Thanks in advance,
Laurent
More information about the Gcc-patches
mailing list