Request to change implementation of TStringList.QuickSort
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
TstringList.QuickSort is a private method that cannot be overridden.
QuickSort calls teh private method ExchangeItems to swap items.
ExchangeItems is optimized for performance and does not do checking of indexes, nor does it call changing/changed.
That is left to the calling procedures: Exchange and QuickSort.
Since ExchangeItems is private, the programmer can only override Exchange to influence how Exchangin items must be done.
Consider the following scenario:
In Lazarus we have a TValueListEditor component. One of it's properties is a component derived from TStringList.
This particular list needs te be in sync with another list of objects.
While, for the most part, this can easily be done by overriding Insert(), Delete() and Exchange(), this approach will fail for (Custom)Sort, since it does not use the overridden version of Exchange but directly calls ExchangeItems.
For now this is solved by copying the functionality of QuickSort and there call Exchange instead.
This however has the distinct disadvantage of having to maintain duplicate code.
On the pascal mailinglist (http://lists.freepascal.org/lists/fpc-pascal/2013-February/036471.html) a solution suggested where QuickSort checks if Exchange is overridden, and if so calls the overriden Exchange, otherwise the default ExchangeItems.
Steps to reproduce:
N/A
Mantis conversion info:
- Mantis ID: 23899
- OS: Window
- OS Build: Win7
- Platform: i386
- Fixed in version: 3.0.0
- Fixed in revision: 25480 (#08543dde)
- Monitored by: » luizamerico (Luiz Americo)