View Issue Details

IDProjectCategoryView StatusLast Update
0036270FPCRTLpublic2019-11-15 15:12
ReporterAlexey Tor.Assigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.3.1Product Build 
Target VersionFixed in Version3.3.1 
Summary0036270: TFPSList.Assign and .AddList can be faster
Descriptionhttps://github.com/graemeg/freepascal/blob/master/rtl/objpas/fgl.pp

procedure TFPSList.AddList(Obj: TFPSList);
var
  i: Integer;
begin
  if Obj.ItemSize <> FItemSize then
    Error(SListItemSizeError, 0);
  for I := 0 to Obj.Count - 1 do
    Add(Obj[i]);
end;

Assign() calls Clear then AddList, it's not fast.
But it can be super fast:
- realloc FList to needed size
- Move() data to FList

I need super-fast TFPSList.Assign, pls change it.
TagsNo tags attached.
Fixed in Revision43473.
FPCOldBugId
FPCTarget3.2.0
Attached Files

Activities

Michael Van Canneyt

2019-11-06 11:58

administrator   ~0119097

I don't think a move is correct.
For simple things as an integer, or a class pointer, this will work. But sometimes there are things to be taken into account such as ref. counting when strings are involved, or interfaces.

I'm not an expert, but I think the best that can be done is to set the capacity prior to doing the loop.

Ugochukwu Mmaduekwe

2019-11-06 19:14

reporter   ~0119109

Last edited: 2019-11-06 19:18

View 4 revisions

@micheal, you are right.
Using Move on data types like strings and interfaces will surely break reference counting.
This is one of the many places where intrinsic compiler functions such as
function IsManagedType(T: TypeIdentifier): Boolean;
suggested here https://bugs.freepascal.org/view.php?id=28357 will come in handy. 😁
If available, we would use it to perform a check which the compiler can determine during compile time and use it to produce optimal code.

Thaddy de Koning

2019-11-09 12:16

reporter   ~0119173

IsManagedType is in latest trunk, Sven added it this week.

Michael Van Canneyt

2019-11-15 15:12

administrator   ~0119318

Fixed using new IsTypeManaged. Please test and close if OK.

Issue History

Date Modified Username Field Change
2019-11-06 11:41 Alexey Tor. New Issue
2019-11-06 11:58 Michael Van Canneyt Note Added: 0119097
2019-11-06 19:14 Ugochukwu Mmaduekwe Note Added: 0119109
2019-11-06 19:15 Ugochukwu Mmaduekwe Note Edited: 0119109 View Revisions
2019-11-06 19:15 Ugochukwu Mmaduekwe Note Edited: 0119109 View Revisions
2019-11-06 19:18 Ugochukwu Mmaduekwe Note Edited: 0119109 View Revisions
2019-11-09 12:16 Thaddy de Koning Note Added: 0119173
2019-11-15 15:12 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-11-15 15:12 Michael Van Canneyt Status new => resolved
2019-11-15 15:12 Michael Van Canneyt Resolution open => fixed
2019-11-15 15:12 Michael Van Canneyt Fixed in Version => 3.3.1
2019-11-15 15:12 Michael Van Canneyt Fixed in Revision => 43473.
2019-11-15 15:12 Michael Van Canneyt FPCTarget => 3.2.0
2019-11-15 15:12 Michael Van Canneyt Note Added: 0119318