diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-08-31 10:23:37 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-08-31 10:23:37 +0000 |
commit | df20d1a8586235a388bc677a7199fe689bead575 (patch) | |
tree | 198081394ea01406fbc6cf4d9510dc38574a8add /gcc/ada/sem_eval.adb | |
parent | 78976972ae3ef0881f018102a8104db0e3e2ac67 (diff) | |
download | gcc-df20d1a8586235a388bc677a7199fe689bead575.tar.gz |
2007-08-31 Bob Duff <duff@adacore.com>
* par-ch4.adb (P_Simple_Expression): Fold long sequences of
concatenations of string literals into a single literal, in order to
avoid very deep recursion in the front end, which was causing stack
overflow.
* sem_eval.adb (Eval_Concatenation): If the left operand is the empty
string, and the right operand is a string literal (the case of "" &
"..."), optimize by avoiding copying the right operand -- just use the
value of the right operand directly.
* stringt.adb (Store_String_Chars): Optimize by growing the
String_Chars table all at once, rather than appending characters one by
one.
(Write_String_Table_Entry): If the string to be printed is very long,
just print the first few characters, followed by the length. Otherwise,
doing "pn(n)" in the debugger can take an extremely long time.
* sem_prag.adb (Process_Interface_Name): Replace loop doing
Store_String_Char with Store_String_Chars.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127977 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/sem_eval.adb')
-rw-r--r-- | gcc/ada/sem_eval.adb | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index dba6ae83946..465a86a3d58 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -1451,9 +1451,10 @@ package body Sem_Eval is -- concatenations with such aggregates. declare - Left_Str : constant Node_Id := Get_String_Val (Left); - Left_Len : Nat; - Right_Str : constant Node_Id := Get_String_Val (Right); + Left_Str : constant Node_Id := Get_String_Val (Left); + Left_Len : Nat; + Right_Str : constant Node_Id := Get_String_Val (Right); + Folded_Val : String_Id; begin -- Establish new string literal, and store left operand. We make @@ -1465,26 +1466,36 @@ package body Sem_Eval is if Nkind (Left_Str) = N_String_Literal then Left_Len := String_Length (Strval (Left_Str)); - Start_String (Strval (Left_Str)); + + -- If the left operand is the empty string, and the right operand + -- is a string literal (the case of "" & "..."), the result is the + -- value of the right operand. This optimization is important when + -- Is_Folded_In_Parser, to avoid copying an enormous right + -- operand. + + if Left_Len = 0 and then Nkind (Right_Str) = N_String_Literal then + Folded_Val := Strval (Right_Str); + else + Start_String (Strval (Left_Str)); + end if; + else Start_String; Store_String_Char (UI_To_CC (Char_Literal_Value (Left_Str))); Left_Len := 1; end if; - -- Now append the characters of the right operand + -- Now append the characters of the right operand, unless we + -- optimized the "" & "..." case above. if Nkind (Right_Str) = N_String_Literal then - declare - S : constant String_Id := Strval (Right_Str); - - begin - for J in 1 .. String_Length (S) loop - Store_String_Char (Get_String_Char (S, J)); - end loop; - end; + if Left_Len /= 0 then + Store_String_Chars (Strval (Right_Str)); + Folded_Val := End_String; + end if; else Store_String_Char (UI_To_CC (Char_Literal_Value (Right_Str))); + Folded_Val := End_String; end if; Set_Is_Static_Expression (N, Stat); @@ -1501,7 +1512,7 @@ package body Sem_Eval is Set_Etype (N, Etype (Right)); end if; - Fold_Str (N, End_String, Static => True); + Fold_Str (N, Folded_Val, Static => True); end if; end; end Eval_Concatenation; |