Skip to content

Commit

Permalink
Forum: sorting on plugin panels is too slow
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Jun 7, 2021
1 parent a5ebad9 commit 67d1e6f
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 48 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
drkns 07.06.2021 23:54:29 +0100 - build 5816

1. Forum: sorting on plugin panels is too slow.

--------------------------------------------------------------------------------
drkns 07.06.2021 22:28:28 +0100 - build 5815

Expand Down
42 changes: 15 additions & 27 deletions far/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ class list_less
{
const auto& [a, b] = m_Reverse? std::tie(Item2, Item1) : std::tie(Item1, Item2);

PluginPanelItemHolder pi1, pi2;
// Direct access, no copy. It's its own panel anyways.
PluginPanelItemHolderRef pi1, pi2;
m_Owner->FileListToPluginItem(a, pi1);
m_Owner->FileListToPluginItem(b, pi2);
if (const auto Result = Global->CtrlObject->Plugins->Compare(m_SortPlugin, &pi1.Item, &pi2.Item, internal_sort_mode_to_plugin(m_ListSortMode)))
Expand Down Expand Up @@ -1876,7 +1877,7 @@ bool FileList::ProcessKey(const Manager::Key& Key)

if (!NewFile)
{
PluginPanelItemHolder PanelItem;
PluginPanelItemHolderHeap PanelItem;
FileListToPluginItem(*CurPtr, PanelItem);

if (!Global->CtrlObject->Plugins->GetFile(GetPluginHandle(), &PanelItem.Item, TemporaryDirectory, strFileName, OPM_SILENT | (Edit? OPM_EDIT : OPM_VIEW)))
Expand Down Expand Up @@ -1958,7 +1959,7 @@ bool FileList::ProcessKey(const Manager::Key& Key)

if (PluginMode && UploadFile)
{
PluginPanelItemHolder PanelItem;
PluginPanelItemHolderHeap PanelItem;
const auto strSaveDir = os::fs::GetCurrentDirectory();

if (!os::fs::exists(strTempName))
Expand Down Expand Up @@ -2691,7 +2692,7 @@ void FileList::ProcessEnter(bool EnableExec,bool SeparateWindow,bool EnableAssoc
LOGWARNING(L"create_directory({}): {}"sv, strTempDir, last_error());
}

PluginPanelItemHolder PanelItem;
PluginPanelItemHolderHeap PanelItem;
FileListToPluginItem(CurItem, PanelItem);

if (!Global->CtrlObject->Plugins->GetFile(GetPluginHandle(), &PanelItem.Item, strTempDir, strFileName, OPM_SILENT | OPM_EDIT))
Expand Down Expand Up @@ -2761,7 +2762,7 @@ void FileList::ProcessEnter(bool EnableExec,bool SeparateWindow,bool EnableAssoc
{
if (file_state::get(strFileName) != SavedState)
{
PluginPanelItemHolder PanelItem;
PluginPanelItemHolderHeap PanelItem;
if (FileNameToPluginItem(strFileName, PanelItem))
{
int PutCode = Global->CtrlObject->Plugins->PutFiles(GetPluginHandle(), { &PanelItem.Item, 1 }, false, OPM_EDIT);
Expand Down Expand Up @@ -4163,7 +4164,7 @@ void FileList::UpdateViewPanel()
LOGWARNING(L"create_directory({}): {}"sv, strTempDir, last_error());
}

PluginPanelItemHolder PanelItem;
PluginPanelItemHolderHeap PanelItem;
FileListToPluginItem(Current, PanelItem);
string strFileName;

Expand Down Expand Up @@ -5458,7 +5459,7 @@ bool FileList::PopPlugin(int EnableRestoreViewMode)

if (CurPlugin->m_Modified)
{
PluginPanelItemHolder PanelItem={};
PluginPanelItemHolderHeap PanelItem={};
const auto strSaveDir = os::fs::GetCurrentDirectory();

if (FileNameToPluginItem(CurPlugin->m_HostFile, PanelItem))
Expand Down Expand Up @@ -5596,30 +5597,17 @@ void FileList::FileListToPluginItem(const FileListItem& fi, PluginPanelItemHolde
FileListItemToPluginPanelItemBasic(fi, pi);
pi.NumberOfLinks = fi.IsNumberOfLinksRead() ? fi.NumberOfLinks(this) : 0;

const auto MakeCopy = [](string_view const Str)
{
auto Buffer = std::make_unique<wchar_t[]>(Str.size() + 1);
*copy_string(Str, Buffer.get()) = {};
return Buffer.release();
};

pi.FileName = MakeCopy(fi.FileName);
pi.AlternateFileName = MakeCopy(fi.AlternateFileName());

auto ColumnData = std::make_unique<const wchar_t*[]>(fi.CustomColumns.size());
for (size_t i = 0; i != fi.CustomColumns.size(); ++i)
{
ColumnData[i] = fi.CustomColumns[i]? MakeCopy(fi.CustomColumns[i]) : nullptr;
}
pi.CustomColumnData = ColumnData.release();
Holder.set_name(fi.FileName);
Holder.set_alt_name(fi.AlternateFileName());
Holder.set_columns(fi.CustomColumns);

if (fi.DizText)
pi.Description = MakeCopy(fi.DizText);
Holder.set_description(fi.DizText);

if (fi.IsOwnerRead())
{
if (const auto& Owner = fi.Owner(this); !Owner.empty())
pi.Owner = MakeCopy(Owner);
Holder.set_owner(Owner);
}
}

Expand Down Expand Up @@ -5816,7 +5804,7 @@ plugin_item_list FileList::CreatePluginItemList()

const auto ConvertAndAddToList = [&](const FileListItem& What)
{
PluginPanelItemHolderNonOwning NewItem;
PluginPanelItemHolderHeapNonOwning NewItem;
FileListToPluginItem(What, NewItem);
ItemList.emplace_back(NewItem.Item);
};
Expand Down Expand Up @@ -5920,7 +5908,7 @@ void FileList::PutDizToPlugin(FileList *DestPanel, const std::vector<PluginPanel
if (Move)
SrcDiz->Flush({});

PluginPanelItemHolder PanelItem;
PluginPanelItemHolderHeap PanelItem;
if (FileNameToPluginItem(strDizName, PanelItem))
{
Global->CtrlObject->Plugins->PutFiles(DestPanel->GetPluginHandle(), { &PanelItem.Item, 1 }, false, OPM_SILENT | OPM_DESCR);
Expand Down
2 changes: 1 addition & 1 deletion far/findfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2766,7 +2766,7 @@ bool FindFiles::FindFilesProcess()
{
i.FindData.FileName = i.Arc->strArcName;
}
PluginPanelItemHolderNonOwning pi;
PluginPanelItemHolderHeapNonOwning pi;
FindDataExToPluginPanelItemHolder(i.FindData, pi);

if (IsArchive)
Expand Down
74 changes: 65 additions & 9 deletions far/mix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,78 @@ void FindDataExToPluginPanelItemHolder(const os::fs::find_data& Src, PluginPanel
Dest.FileAttributes = Src.Attributes;
Dest.NumberOfLinks = 1;

const auto MakeCopy = [](string_view const Str)
{
auto Buffer = std::make_unique<wchar_t[]>(Str.size() + 1);
*copy_string(Str, Buffer.get()) = {};
return Buffer.release();
};
Holder.set_name(Src.FileName);
Holder.set_alt_name(Src.AlternateFileName());
}

void PluginPanelItemHolderRef::set_name(string_view Value)
{
Item.FileName = Value.data();
}

Dest.FileName = MakeCopy(Src.FileName);
Dest.AlternateFileName = MakeCopy(Src.AlternateFileName());
void PluginPanelItemHolderRef::set_alt_name(string_view Value)
{
Item.AlternateFileName = Value.data();
}

void PluginPanelItemHolderRef::set_description(string_view Value)
{
Item.Description = Value.data();
}

PluginPanelItemHolder::~PluginPanelItemHolder()
void PluginPanelItemHolderRef::set_owner(string_view Value)
{
Item.Owner = Value.data();
}

void PluginPanelItemHolderRef::set_columns(span<const wchar_t* const> Value)
{
Item.CustomColumnData = Value.data();
}

PluginPanelItemHolderHeap::~PluginPanelItemHolderHeap()
{
FreePluginPanelItemData(Item);
}

void PluginPanelItemHolderHeap::set_name(string_view const Value)
{
Item.FileName = make_copy(Value);
}

void PluginPanelItemHolderHeap::set_alt_name(string_view const Value)
{
Item.AlternateFileName = make_copy(Value);
}

void PluginPanelItemHolderHeap::set_description(string_view const Value)
{
Item.Description = make_copy(Value);
}

void PluginPanelItemHolderHeap::set_owner(string_view const Value)
{
Item.Owner = make_copy(Value);
}

void PluginPanelItemHolderHeap::set_columns(span<const wchar_t* const> const Value)
{
auto ColumnData = std::make_unique<const wchar_t* []>(Value.size());
for (size_t i = 0; i != Value.size(); ++i)
{
ColumnData[i] = Value[i]? make_copy(Value[i]) : nullptr;
}

Item.CustomColumnData = ColumnData.release();
}

const wchar_t* PluginPanelItemHolderHeap::make_copy(string_view const Value)
{
auto Buffer = std::make_unique<wchar_t[]>(Value.size() + 1);
*copy_string(Value, Buffer.get()) = {};
return Buffer.release();
}

void FreePluginPanelItemData(const PluginPanelItem& Data)
{
delete[] Data.FileName;
Expand Down
46 changes: 40 additions & 6 deletions far/mix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,52 @@ void PluginPanelItemToFindDataEx(const PluginPanelItem& Src, os::fs::find_data&
class PluginPanelItemHolder
{
public:
NONCOPYABLE(PluginPanelItemHolder);

PluginPanelItemHolder() = default;
~PluginPanelItemHolder();
virtual void set_name(string_view Value) = 0;
virtual void set_alt_name(string_view Value) = 0;
virtual void set_description(string_view Value) = 0;
virtual void set_owner(string_view Value) = 0;
virtual void set_columns(span<const wchar_t* const> Value) = 0;

PluginPanelItem Item{};

protected:
virtual ~PluginPanelItemHolder() = default;
};

class PluginPanelItemHolderRef: public PluginPanelItemHolder
{
public:
~PluginPanelItemHolderRef() override = default;

void set_name(string_view Value) override;
void set_alt_name(string_view Value) override;
void set_description(string_view Value) override;
void set_owner(string_view Value) override;
void set_columns(span<const wchar_t* const> Value) override;
};

class PluginPanelItemHolderHeap: public PluginPanelItemHolder
{
public:
NONCOPYABLE(PluginPanelItemHolderHeap);

PluginPanelItemHolderHeap() = default;
~PluginPanelItemHolderHeap() override;

void set_name(string_view Value) override;
void set_alt_name(string_view Value) override;
void set_description(string_view Value) override;
void set_owner(string_view Value) override;
void set_columns(span<const wchar_t* const> Value) override;

private:
static const wchar_t* make_copy(string_view Value);
};

class PluginPanelItemHolderNonOwning: public PluginPanelItemHolder
class PluginPanelItemHolderHeapNonOwning: public PluginPanelItemHolderHeap
{
public:
~PluginPanelItemHolderNonOwning()
~PluginPanelItemHolderHeapNonOwning() override
{
Item = {};
}
Expand Down
4 changes: 2 additions & 2 deletions far/plugapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ intptr_t WINAPI apiGetDirList(const wchar_t *Dir,PluginPanelItem **pPanelItem,si
}

FindData.FileName = strFullName;
PluginPanelItemHolderNonOwning Item;
PluginPanelItemHolderHeapNonOwning Item;
FindDataExToPluginPanelItemHolder(FindData, Item);
Items->emplace_back(Item.Item);
}
Expand Down Expand Up @@ -2969,7 +2969,7 @@ void WINAPI apiRecursiveSearch(const wchar_t *InitDir, const wchar_t *Mask, FRSU
{
if (FMask.check(FindData.FileName))
{
PluginPanelItemHolder fdata;
PluginPanelItemHolderHeap fdata;
FindDataExToPluginPanelItemHolder(FindData, fdata);
Found = !Func(&fdata.Item, strFullName.c_str(), Param);
}
Expand Down
2 changes: 1 addition & 1 deletion far/print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void PrintFiles(FileList* SrcPanel)
if (!ListItem)
throw MAKE_FAR_EXCEPTION(L"GetLastSelectedItem error"sv);

PluginPanelItemHolder PanelItem;
PluginPanelItemHolderHeap PanelItem;
SrcPanel->FileListToPluginItem(*ListItem, PanelItem);

if (!Global->CtrlObject->Plugins->GetFile(hPlugin, &PanelItem.Item, strTempDir, FileName, OPM_SILENT))
Expand Down
2 changes: 1 addition & 1 deletion far/treelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ bool TreeList::ProcessKey(const Manager::Key& Key)

if (ToPlugin)
{
PluginPanelItemHolder Item;
PluginPanelItemHolderHeap Item;
const auto hAnotherPlugin = AnotherPanel->GetPluginHandle();
if (FileList::FileNameToPluginItem(m_ListData[m_CurFile].strName, Item))
{
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5815
5816

0 comments on commit 67d1e6f

Please sign in to comment.