Skip to content

Commit

Permalink
[collections] performance changes
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Apr 22, 2020
1 parent be1425b commit 7f73ee1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Quick.Collections.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Author : Kike Pérez
Version : 1.2
Created : 07/03/2020
Modified : 31/03/2020
Modified : 07/04/2020
This file is part of QuickLib: https://github.com/exilon/QuickLib
Expand Down Expand Up @@ -98,6 +98,7 @@ interface
IList<T> = interface(IListBase<T>)
['{78952BD5-7D15-42BB-ADCB-2F835DF879A0}']
function Any(const aMatchString : string; aUseRegEx : Boolean) : Boolean; overload;
function Any(const aWhereClause : string; aValues : array of const) : Boolean; overload;
function Where(const aMatchString : string; aUseRegEx : Boolean) : ILinqArray<T>; overload;
function Where(const aWhereClause : string; aWhereValues : array of const) : ILinqQuery<T>; overload;
function Where(const aWhereClause: string): ILinqQuery<T>; overload;
Expand Down Expand Up @@ -173,6 +174,7 @@ TxList<T> = class(TInterfacedObject,IList<T>)
function Where(const aWhereClause : string; aWhereValues : array of const) : ILinqQuery<T>; overload;
function Where(const aWhereClause: string): ILinqQuery<T>; overload;
function Any(const aMatchString : string; aUseRegEx : Boolean) : Boolean; overload;
function Any(const aWhereClause : string; aValues : array of const) : Boolean; overload; virtual;
function Where(const aMatchString : string; aUseRegEx : Boolean) : ILinqArray<T>; overload;
{$IFNDEF FPC}
function Where(aPredicate : TPredicate<T>) : ILinqQuery<T>; overload;
Expand All @@ -186,7 +188,7 @@ TxObjectList<T : class> = class(TxList<T>,IObjectList<T>)
public
constructor Create(aOwnedObjects : Boolean = True);
destructor Destroy; override;
function Any(const aWhereClause : string; aValues : array of const) : Boolean; overload;
function Any(const aWhereClause : string; aValues : array of const) : Boolean; overload; override;
function Where(const aWhereClause : string; aWhereValues : array of const) : ILinqQuery<T>; overload;
function Where(const aWhereClause: string): ILinqQuery<T>; overload;
function Where(aPredicate : TPredicate<T>): ILinqQuery<T>; overload;
Expand Down Expand Up @@ -301,13 +303,15 @@ procedure TxList<T>.FromList(const aList: TList<T>);
var
value : T;
begin
fList.Capacity := aList.Count;
for value in aList do fList.Add(value);
end;

procedure TxList<T>.FromArray(const aArray: TArray<T>);
var
value : T;
begin
fList.Capacity := High(aArray);
for value in aArray do fList.Add(value);
end;

Expand Down Expand Up @@ -436,6 +440,7 @@ function TxList<T>.ToList: TList<T>;
value : T;
begin
Result := TList<T>.Create;
Result.Capacity := fList.Count;
for value in fList do Result.Add(value);
end;

Expand Down Expand Up @@ -468,6 +473,11 @@ function TxList<T>.Where(aPredicate: TPredicate<T>): ILinqQuery<T>;
Result := TLinqQuery<TObject>.Create(TObjectList<TObject>(Self.fList)).Where(TPredicate<TObject>(aPredicate)) as ILinqQuery<T>;
end;

function TxList<T>.Any(const aWhereClause: string; aValues: array of const): Boolean;
begin
Result := Where(aWhereClause,aValues).Count > 0;
end;

{ TXObjectList<T> }

function TxObjectList<T>.Any(const aWhereClause: string; aValues: array of const): Boolean;
Expand Down

0 comments on commit 7f73ee1

Please sign in to comment.