View Issue Details

IDProjectCategoryView StatusLast Update
0035341FPCRTLpublic2019-04-08 09:53
ReporterOndrej PokornyAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version3.3.1Product Build 
Target Version3.2.0Fixed in Version3.3.1 
Summary0035341: TStrings.AddStrings don't use BeginUpdate-EndUpdate
DescriptionBoth overloads:
Procedure TStrings.AddStrings(const TheStrings: array of string);
Procedure TStrings.AddStrings(TheStrings: TStrings);

do not use BeginUpdate-EndUpdate block and so TStringList.Changed is executed for every string added.

Furthermore
Procedure TStrings.AddStrings(TheStrings: TStrings; ClearFirst : Boolean);
doesn't increase the capacity before adding.
Steps To Reproduceprogram Project1;

uses
  Classes;

var
  S1, S2: TStringList;
begin
  S1 := TStringList.Create;
  S2 := TStringList.Create;
  try
    S1.Add('x');
    S1.Add('y');

    S2.AddStrings(S1);
    S2.AddStrings(['a', 'b']);

    Writeln(S2.Text);
  finally
    S1.Free;
    S2.Free;
  end;
end.
Additional InformationPatch attached.
TagsNo tags attached.
Fixed in Revision41849
FPCOldBugId
FPCTarget
Attached Files
  • stringl-AddStrings.patch (1,708 bytes)
    Index: rtl/objpas/classes/stringl.inc
    ===================================================================
    --- rtl/objpas/classes/stringl.inc	(revision 41848)
    +++ rtl/objpas/classes/stringl.inc	(working copy)
    @@ -779,13 +779,16 @@
     
     Procedure TStrings.AddStrings(TheStrings: TStrings; ClearFirst : Boolean);
     
    -
    +Var Runner : longint;
     begin
       beginupdate;
       try
         if ClearFirst then
           Clear;
    -    AddStrings(TheStrings);
    +    if Count + TheStrings.Count > Capacity then
    +      Capacity := Count + TheStrings.Count;
    +    For Runner:=0 to TheStrings.Count-1 do
    +      self.AddObject (Thestrings[Runner],TheStrings.Objects[Runner]);
       finally
         EndUpdate;
       end;
    @@ -793,31 +796,28 @@
     
     Procedure TStrings.AddStrings(TheStrings: TStrings);
     
    -Var Runner : longint;
     begin
    -  For Runner:=0 to TheStrings.Count-1 do
    -    self.AddObject (Thestrings[Runner],TheStrings.Objects[Runner]);
    +  AddStrings(TheStrings, False);
     end;
     
     Procedure TStrings.AddStrings(const TheStrings: array of string);
     
    -Var Runner : longint;
     begin
    -  if Count + High(TheStrings)+1 > Capacity then
    -    Capacity := Count + High(TheStrings)+1;
    -  For Runner:=Low(TheStrings) to High(TheStrings) do
    -    self.Add(Thestrings[Runner]);
    +  AddStrings(TheStrings, False);
     end;
     
     Procedure TStrings.AddStrings(const TheStrings: array of string; ClearFirst : Boolean);
     
    -
    +Var Runner : longint;
     begin
       beginupdate;
       try
         if ClearFirst then
           Clear;
    -    AddStrings(TheStrings);
    +    if Count + High(TheStrings)+1 > Capacity then
    +      Capacity := Count + High(TheStrings)+1;
    +    For Runner:=Low(TheStrings) to High(TheStrings) do
    +      self.Add(Thestrings[Runner]);
       finally
         EndUpdate;
       end;
    
    stringl-AddStrings.patch (1,708 bytes)

Activities

Ondrej Pokorny

2019-04-08 08:42

reporter  

stringl-AddStrings.patch (1,708 bytes)
Index: rtl/objpas/classes/stringl.inc
===================================================================
--- rtl/objpas/classes/stringl.inc	(revision 41848)
+++ rtl/objpas/classes/stringl.inc	(working copy)
@@ -779,13 +779,16 @@
 
 Procedure TStrings.AddStrings(TheStrings: TStrings; ClearFirst : Boolean);
 
-
+Var Runner : longint;
 begin
   beginupdate;
   try
     if ClearFirst then
       Clear;
-    AddStrings(TheStrings);
+    if Count + TheStrings.Count > Capacity then
+      Capacity := Count + TheStrings.Count;
+    For Runner:=0 to TheStrings.Count-1 do
+      self.AddObject (Thestrings[Runner],TheStrings.Objects[Runner]);
   finally
     EndUpdate;
   end;
@@ -793,31 +796,28 @@
 
 Procedure TStrings.AddStrings(TheStrings: TStrings);
 
-Var Runner : longint;
 begin
-  For Runner:=0 to TheStrings.Count-1 do
-    self.AddObject (Thestrings[Runner],TheStrings.Objects[Runner]);
+  AddStrings(TheStrings, False);
 end;
 
 Procedure TStrings.AddStrings(const TheStrings: array of string);
 
-Var Runner : longint;
 begin
-  if Count + High(TheStrings)+1 > Capacity then
-    Capacity := Count + High(TheStrings)+1;
-  For Runner:=Low(TheStrings) to High(TheStrings) do
-    self.Add(Thestrings[Runner]);
+  AddStrings(TheStrings, False);
 end;
 
 Procedure TStrings.AddStrings(const TheStrings: array of string; ClearFirst : Boolean);
 
-
+Var Runner : longint;
 begin
   beginupdate;
   try
     if ClearFirst then
       Clear;
-    AddStrings(TheStrings);
+    if Count + High(TheStrings)+1 > Capacity then
+      Capacity := Count + High(TheStrings)+1;
+    For Runner:=Low(TheStrings) to High(TheStrings) do
+      self.Add(Thestrings[Runner]);
   finally
     EndUpdate;
   end;
stringl-AddStrings.patch (1,708 bytes)

Michael Van Canneyt

2019-04-08 09:51

administrator   ~0115322

Applied, thanks for the patch!

Ondrej Pokorny

2019-04-08 09:53

reporter   ~0115323

Thank you!

Issue History

Date Modified Username Field Change
2019-04-08 08:42 Ondrej Pokorny New Issue
2019-04-08 08:42 Ondrej Pokorny File Added: stringl-AddStrings.patch
2019-04-08 09:49 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-04-08 09:49 Michael Van Canneyt Status new => assigned
2019-04-08 09:51 Michael Van Canneyt Fixed in Revision => 41849
2019-04-08 09:51 Michael Van Canneyt Note Added: 0115322
2019-04-08 09:51 Michael Van Canneyt Status assigned => resolved
2019-04-08 09:51 Michael Van Canneyt Fixed in Version => 3.3.1
2019-04-08 09:51 Michael Van Canneyt Resolution open => fixed
2019-04-08 09:51 Michael Van Canneyt Target Version => 3.2.0
2019-04-08 09:53 Ondrej Pokorny Note Added: 0115323
2019-04-08 09:53 Ondrej Pokorny Status resolved => closed