From 7f73ee17d51c9d781fdaf2f8e1202896414cf592 Mon Sep 17 00:00:00 2001 From: Exilon Date: Wed, 22 Apr 2020 15:48:28 +0200 Subject: [PATCH] [collections] performance changes --- Quick.Collections.pas | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Quick.Collections.pas b/Quick.Collections.pas index 87d08ee..5757ad9 100644 --- a/Quick.Collections.pas +++ b/Quick.Collections.pas @@ -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 @@ -98,6 +98,7 @@ interface IList = interface(IListBase) ['{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; overload; function Where(const aWhereClause : string; aWhereValues : array of const) : ILinqQuery; overload; function Where(const aWhereClause: string): ILinqQuery; overload; @@ -173,6 +174,7 @@ TxList = class(TInterfacedObject,IList) function Where(const aWhereClause : string; aWhereValues : array of const) : ILinqQuery; overload; function Where(const aWhereClause: string): ILinqQuery; 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; overload; {$IFNDEF FPC} function Where(aPredicate : TPredicate) : ILinqQuery; overload; @@ -186,7 +188,7 @@ TxObjectList = class(TxList,IObjectList) 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; overload; function Where(const aWhereClause: string): ILinqQuery; overload; function Where(aPredicate : TPredicate): ILinqQuery; overload; @@ -301,6 +303,7 @@ procedure TxList.FromList(const aList: TList); var value : T; begin + fList.Capacity := aList.Count; for value in aList do fList.Add(value); end; @@ -308,6 +311,7 @@ procedure TxList.FromArray(const aArray: TArray); var value : T; begin + fList.Capacity := High(aArray); for value in aArray do fList.Add(value); end; @@ -436,6 +440,7 @@ function TxList.ToList: TList; value : T; begin Result := TList.Create; + Result.Capacity := fList.Count; for value in fList do Result.Add(value); end; @@ -468,6 +473,11 @@ function TxList.Where(aPredicate: TPredicate): ILinqQuery; Result := TLinqQuery.Create(TObjectList(Self.fList)).Where(TPredicate(aPredicate)) as ILinqQuery; end; +function TxList.Any(const aWhereClause: string; aValues: array of const): Boolean; +begin + Result := Where(aWhereClause,aValues).Count > 0; +end; + { TXObjectList } function TxObjectList.Any(const aWhereClause: string; aValues: array of const): Boolean;