From c6d8bd73f7343b8fa6ae514e6187786542468b4c Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 9 Oct 2019 07:13:37 +0000 Subject: [PATCH] * Patch from Serge Anvarov with some optimizations (bug ID 36143) git-svn-id: trunk@43155 - --- rtl/objpas/classes/classesh.inc | 38 ++++++++++++++------------------- rtl/objpas/classes/lists.inc | 16 ++------------ 2 files changed, 18 insertions(+), 36 deletions(-) diff --git a/rtl/objpas/classes/classesh.inc b/rtl/objpas/classes/classesh.inc index 193715ad38..4d6ff0711a 100644 --- a/rtl/objpas/classes/classesh.inc +++ b/rtl/objpas/classes/classesh.inc @@ -242,7 +242,7 @@ Type function Add(Item: Pointer): Integer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE} procedure Clear; procedure Delete(Index: Integer); {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE} - class procedure Error(const Msg: string; Data: PtrInt); + class procedure Error(const Msg: string; Data: PtrInt); static; procedure Exchange(Index1, Index2: Integer); function Expand: TFPList; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE} function Extract(Item: Pointer): Pointer; @@ -288,15 +288,9 @@ Type TListNotification = (lnAdded, lnExtracted, lnDeleted); TList = class; - TListEnumerator = class - private - FList: TList; - FPosition: Integer; + TListEnumerator = class(TFPListEnumerator) public constructor Create(AList: TList); - function GetCurrent: Pointer; - function MoveNext: Boolean; - property Current: Pointer read GetCurrent; end; TList = class(TObject,IFPObserved) @@ -312,15 +306,15 @@ Type procedure DoOr(ListA, ListB : TList); procedure DoXOr(ListA, ListB : TList); protected - function Get(Index: Integer): Pointer; + function Get(Index: Integer): Pointer; inline; procedure Grow; virtual; procedure Put(Index: Integer; Item: Pointer); procedure Notify(Ptr: Pointer; Action: TListNotification); virtual; - procedure SetCapacity(NewCapacity: Integer); - function GetCapacity: integer; + procedure SetCapacity(NewCapacity: Integer); inline; + function GetCapacity: Integer; inline; procedure SetCount(NewCount: Integer); - function GetCount: integer; - function GetList: PPointerList; + function GetCount: Integer; inline; + function GetList: PPointerList; inline; public constructor Create; destructor Destroy; override; @@ -335,19 +329,19 @@ Type procedure Exchange(Index1, Index2: Integer); function Expand: TList; function Extract(item: Pointer): Pointer; - function First: Pointer; + function First: Pointer; inline; function GetEnumerator: TListEnumerator; - function IndexOf(Item: Pointer): Integer; + function IndexOf(Item: Pointer): Integer; inline; procedure Insert(Index: Integer; Item: Pointer); - function Last: Pointer; - procedure Move(CurIndex, NewIndex: Integer); + function Last: Pointer; inline; + procedure Move(CurIndex, NewIndex: Integer); inline; procedure Assign (ListA: TList; AOperator: TListAssignOp=laCopy; ListB: TList=nil); function Remove(Item: Pointer): Integer; - procedure Pack; - procedure Sort(Compare: TListSortCompare); - procedure Sort(Compare: TListSortCompare; SortingAlgorithm: PSortingAlgorithm); - procedure Sort(Compare: TListSortComparer_Context; Context: Pointer); - procedure Sort(Compare: TListSortComparer_Context; Context: Pointer; SortingAlgorithm: PSortingAlgorithm); + procedure Pack; inline; + procedure Sort(Compare: TListSortCompare); inline; + procedure Sort(Compare: TListSortCompare; SortingAlgorithm: PSortingAlgorithm); inline; + procedure Sort(Compare: TListSortComparer_Context; Context: Pointer); inline; + procedure Sort(Compare: TListSortComparer_Context; Context: Pointer; SortingAlgorithm: PSortingAlgorithm); inline; property Capacity: Integer read GetCapacity write SetCapacity; property Count: Integer read GetCount write SetCount; property Items[Index: Integer]: Pointer read Get write Put; default; diff --git a/rtl/objpas/classes/lists.inc b/rtl/objpas/classes/lists.inc index cda416bb80..ae9e951023 100644 --- a/rtl/objpas/classes/lists.inc +++ b/rtl/objpas/classes/lists.inc @@ -140,7 +140,7 @@ begin begin SetCount(0); SetCapacity(0); - FList := nil; + // FList := nil; // Already set by SetCapacity end; end; @@ -535,21 +535,9 @@ end; constructor TListEnumerator.Create(AList: TList); begin - inherited Create; - FList := AList; - FPosition := -1; + inherited Create(AList.FList); end; -function TListEnumerator.GetCurrent: Pointer; -begin - Result := FList[FPosition]; -end; - -function TListEnumerator.MoveNext: Boolean; -begin - Inc(FPosition); - Result := FPosition < FList.Count; -end; {****************************************************************************} {* TList *}