[fpc-devel] Questions on TStringList.Find change (Mantis 28744)

David Jenkins david at scootersoftware.com
Tue Mar 22 16:52:11 CET 2016



On 3/22/16 9:53 AM, Denis Kozlov wrote:
>
>
>
> Please consider the following implementation logic, I think it covers 
> all angles:
>
> procedure Find(const S: string; out Index: Integer):Boolean;
> begin
>   if Sorted then
>     Result := FindSorted(S, Index);
>   else
>   begin
>     Index := IndexOf(S);
>     Result := (Index >= 0);
>   end;
> end;
>
> procedure FindSorted(const S: string; out Index: Integer; CheckSorted: 
> Boolean = True):Boolean;
> begin
>   if CheckSorted and not Sorted then
>     raise Exception.Create('List must be sorted');
>   // search logic here...
> end;
>
>
> Denis
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Denis,

I like how this solves the issue of calling find on truly unsorted 
lists.  My only quibble with this is that 'Sorted' still does not 
reflect the actual state of the list.  For a naturally sorted list there 
is still unnecessary calls to sort both in your suggested code above and 
in the existing code (if sorted is set).  Can that be handled as well?  
'Sorted' right now is a request and an expression of state.  As an 
expression of state it is only valid if the request has been first made.

David

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160322/dbc79eb3/attachment.html>


More information about the fpc-devel mailing list