El 24/02/2021 a las 11:47, Bart via lazarus escribió:
On Wed, Feb 24, 2021 at 10:02 AM Bart <bartjun...@gmail.com> wrote:

Of course that is NOT a reason not to improve it: O(n^4) is just terrible.

To put this discussion in a little perspective.
Given a string S (UTF8 encoded) with Utf8Length=1000.
GetCodePoint(S,1000) on my laptop takes 0.00439 msecs to perform.
So 10 thousand of these lookups cost appr. 44 ms.
This is kind of a worst case scenario.
You are not very likely to have strings that long in TMask.MatchesMask
(and certainly not in a MaskEdit).

Hello,

The worst case scenario is not based in GetCodePoint time, is in the TMask logic when "*" is found, it enters in recursive scan from that point, if it founds a new "*" it recurses again and if it finally fails in comparison it rolls back to the first "*". So specially crafted masks makes it recurse a lot.

String:='This is a test string';
Mask:='*T*h*s*n*x';

Of course this is not a day by day use ;-)

Note: Just to put in context, my "explore" in the TMask world started when writing my NTFS filesystem reader, when all file names are read (400,000) I can search for them using masks. When compiled in fpc (Lazarus) the "*.txx" search takes 1-2 seconds (not measured) and when compiled with Delphi it takes +/- 0.3 seconds, so I stated to write my own TMask.


--

--
_______________________________________________
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to