Skip to content

Commit

Permalink
Unnecessary code removed (performance and memory use optimization)
Browse files Browse the repository at this point in the history
  • Loading branch information
VioletGiraffe committed Sep 13, 2024
1 parent 7eafd8e commit 2b2be63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion file-commander-core/src/iconprovider/ciconproviderimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ QIcon CIconProviderImpl::iconFor(const CFileSystemObject& object, const bool gue
if (!guessIconByFileExtension)
{
WCHAR pathStringBuffer[32768];
// TODO: create a helper function for this in cpputils
// This function does not accept UNC paths!
const auto length = object.fullAbsolutePath().toWCharArray(pathStringBuffer);
pathStringBuffer[length] = 0;

Expand Down
25 changes: 8 additions & 17 deletions qt-app/src/panel/cpanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,47 +186,41 @@ void CPanelWidget::fillFromList(const FileListHashMap& items, FileListRefreshCau

int itemRow = 0;

struct TreeViewItem {
const int row;
const FileListViewColumn column;
QStandardItem* const item;
};

std::vector<TreeViewItem> qTreeViewItems;
qTreeViewItems.reserve(items.size() * NumberOfColumns);

const bool useLessPreciseIcons = items.size() > 500;
for (const auto& item: items)
{
const CFileSystemObject& object = item.second;
const auto& props = object.properties();

auto* fileNameItem = new QStandardItem();

fileNameItem->setEditable(false);
if (props.type == Directory)
fileNameItem->setData(QString("[" % (object.isCdUp() ? QLatin1String("..") : props.fullName) % "]"), Qt::DisplayRole);
else if (props.completeBaseName.isEmpty() && props.type == File) // File without a name, displaying extension in the name field and adding point to extension
fileNameItem->setData(QString('.') + props.extension, Qt::DisplayRole);
else
fileNameItem->setData(props.completeBaseName, Qt::DisplayRole);
fileNameItem->setIcon(CIconProvider::iconForFilesystemObject(object, useLessPreciseIcons));

const bool isExeFile = false;//props.type == File && props.extension.compare("exe", Qt::CaseInsensitive) == 0;
fileNameItem->setIcon(CIconProvider::iconForFilesystemObject(object, useLessPreciseIcons && !isExeFile));
fileNameItem->setData(static_cast<qulonglong>(props.hash), Qt::UserRole); // Unique identifier for this object
qTreeViewItems.emplace_back(TreeViewItem{ itemRow, NameColumn, fileNameItem });
_model->setItem(itemRow, NameColumn, fileNameItem);

auto* fileExtItem = new QStandardItem();
fileExtItem->setEditable(false);
if (!object.isCdUp() && !props.completeBaseName.isEmpty() && !props.extension.isEmpty())
fileExtItem->setData(props.extension, Qt::DisplayRole);
fileExtItem->setData(static_cast<qulonglong>(props.hash), Qt::UserRole); // Unique identifier for this object
qTreeViewItems.emplace_back(TreeViewItem{ itemRow, ExtColumn, fileExtItem });
_model->setItem(itemRow, ExtColumn, fileExtItem);

auto* sizeItem = new QStandardItem();
sizeItem->setEditable(false);
if (props.size > 0 || props.type == File)
sizeItem->setData(fileSizeToString(props.size), Qt::DisplayRole);

sizeItem->setData(static_cast<qulonglong>(props.hash), Qt::UserRole); // Unique identifier for this object
qTreeViewItems.emplace_back(TreeViewItem{ itemRow, SizeColumn, sizeItem });
_model->setItem(itemRow, SizeColumn, sizeItem);

auto* dateItem = new QStandardItem();
dateItem->setEditable(false);
Expand All @@ -236,14 +230,11 @@ void CPanelWidget::fillFromList(const FileListHashMap& items, FileListRefreshCau
dateItem->setData(modificationDate.toString(QSL("dd.MM.yyyy hh:mm:ss")), Qt::DisplayRole);
}
dateItem->setData(static_cast<qulonglong>(props.hash), Qt::UserRole); // Unique identifier for this object
qTreeViewItems.emplace_back(TreeViewItem{ itemRow, DateColumn, dateItem });
_model->setItem(itemRow, DateColumn, dateItem);

++itemRow;
}

for (const auto& qTreeViewItem: qTreeViewItems)
_model->setItem(qTreeViewItem.row, qTreeViewItem.column, qTreeViewItem.item);

_sortModel->setSourceModel(_model);

ui->_list->restoreHeaderState();
Expand Down

0 comments on commit 2b2be63

Please sign in to comment.