Commit 7e679b13 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Use more UDSEntry::reserve() calls to avoid reallocs on multiple inserts

Reviewers: #frameworks, sitter, meven

Reviewed By: meven

Subscribers: kde-frameworks-devel, kfm-devel

Tags: #dolphin, #frameworks

Differential Revision: https://phabricator.kde.org/D28538
parent a22f9fad
......@@ -101,6 +101,7 @@ public:
KIO::UDSEntry activityEntry(const QString &activity)
{
KIO::UDSEntry uds;
uds.reserve(8);
KActivities::Info activityInfo(activity);
uds.fastInsert(KIO::UDSEntry::UDS_NAME, activity);
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, activityInfo.name());
......@@ -224,6 +225,7 @@ void ActivitiesProtocol::listDir(const QUrl &url)
KIO::UDSEntryList udslist;
KIO::UDSEntry uds;
uds.reserve(9);
uds.fastInsert(KIO::UDSEntry::UDS_NAME, QStringLiteral("current"));
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, i18n("Current activity"));
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, i18n("Activity"));
......@@ -305,6 +307,7 @@ void ActivitiesProtocol::stat(const QUrl& url)
{
QString dirName = i18n("Activities");
KIO::UDSEntry uds;
uds.reserve(6);
uds.fastInsert(KIO::UDSEntry::UDS_NAME, dirName);
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, dirName);
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, dirName);
......
......@@ -177,6 +177,7 @@ bool ArchiveProtocolBase::checkNewFile( const QUrl & url, QString & path, KIO::E
void ArchiveProtocolBase::createRootUDSEntry( KIO::UDSEntry & entry )
{
entry.clear();
entry.reserve(5);
entry.fastInsert( KIO::UDSEntry::UDS_NAME, "." );
entry.fastInsert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR );
entry.fastInsert( KIO::UDSEntry::UDS_MODIFICATION_TIME, m_mtime );
......@@ -188,6 +189,7 @@ void ArchiveProtocolBase::createRootUDSEntry( KIO::UDSEntry & entry )
void ArchiveProtocolBase::createUDSEntry( const KArchiveEntry * archiveEntry, UDSEntry & entry )
{
entry.clear();
entry.reserve(8);
entry.fastInsert( KIO::UDSEntry::UDS_NAME, archiveEntry->name() );
entry.fastInsert( KIO::UDSEntry::UDS_FILE_TYPE, archiveEntry->permissions() & S_IFMT ); // keep file type only
entry.fastInsert( KIO::UDSEntry::UDS_SIZE, archiveEntry->isFile() ? ((KArchiveFile *)archiveEntry)->size() : 0L );
......@@ -315,6 +317,7 @@ void ArchiveProtocolBase::stat( const QUrl & url )
error( errorNum, url.toDisplayString() );
return;
}
entry.reserve(2);
// Real directory. Return just enough information for KRun to work
entry.fastInsert( KIO::UDSEntry::UDS_NAME, url.fileName());
qCDebug(KIO_ARCHIVE_LOG).nospace() << "ArchiveProtocolBase::stat returning name=" << url.fileName();
......
......@@ -672,6 +672,7 @@ void MANProtocol::stat( const QUrl& url)
qCDebug(KIO_MAN_LOG) << "URL " << url.url() << " parsed to title='" << title << "' section=" << section;
UDSEntry entry;
entry.reserve(3);
entry.fastInsert(KIO::UDSEntry::UDS_NAME, title);
entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG);
entry.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QString::fromLatin1("text/html"));
......@@ -1381,6 +1382,7 @@ void MANProtocol::listDir(const QUrl &url)
if (section.isEmpty()) {
for (QStringList::ConstIterator it = section_names.constBegin(); it != section_names.constEnd(); ++it) {
UDSEntry uds_entry;
uds_entry.reserve(3);
QString name = "man:/(" + *it + ')';
uds_entry.fastInsert( KIO::UDSEntry::UDS_NAME, sectionName( *it ) );
......@@ -1400,6 +1402,7 @@ void MANProtocol::listDir(const QUrl &url)
stripExtension( &(*it) );
UDSEntry uds_entry;
uds_entry.reserve(3);
uds_entry.fastInsert(KIO::UDSEntry::UDS_NAME, *it);
uds_entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG);
uds_entry.fastInsert(KIO::UDSEntry::UDS_MIME_TYPE, QString::fromLatin1("text/html"));
......
......@@ -37,6 +37,7 @@
static UDSEntry getEntry(const KMTPDeviceInterface *device)
{
UDSEntry entry;
entry.reserve(5);
entry.fastInsert(UDSEntry::UDS_NAME, device->friendlyName());
entry.fastInsert(UDSEntry::UDS_ICON_NAME, QStringLiteral("multimedia-player"));
entry.fastInsert(UDSEntry::UDS_FILE_TYPE, S_IFDIR);
......@@ -48,6 +49,7 @@ static UDSEntry getEntry(const KMTPDeviceInterface *device)
static UDSEntry getEntry(const KMTPStorageInterface *storage)
{
UDSEntry entry;
entry.reserve(5);
entry.fastInsert(UDSEntry::UDS_NAME, storage->description());
entry.fastInsert(UDSEntry::UDS_ICON_NAME, QStringLiteral("drive-removable-media"));
entry.fastInsert(UDSEntry::UDS_FILE_TYPE, S_IFDIR);
......@@ -59,6 +61,7 @@ static UDSEntry getEntry(const KMTPStorageInterface *storage)
static UDSEntry getEntry(const KMTPFile &file)
{
UDSEntry entry;
entry.reserve(9);
entry.fastInsert(UDSEntry::UDS_NAME, file.filename());
if (file.isFolder()) {
entry.fastInsert(UDSEntry::UDS_FILE_TYPE, S_IFDIR);
......@@ -175,6 +178,7 @@ void MTPSlave::listDir(const QUrl &url)
// list '.' entry, otherwise files cannot be pasted to empty folders
KIO::UDSEntry entry;
entry.reserve(4);
entry.fastInsert(KIO::UDSEntry::UDS_NAME, QStringLiteral("."));
entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
entry.fastInsert(KIO::UDSEntry::UDS_SIZE, 0);
......@@ -278,6 +282,7 @@ void MTPSlave::stat(const QUrl &url)
UDSEntry entry;
// root
if (pathItems.size() < 1) {
entry.reserve(4);
entry.fastInsert(UDSEntry::UDS_NAME, QLatin1String("mtp:///"));
entry.fastInsert(UDSEntry::UDS_FILE_TYPE, S_IFDIR);
entry.fastInsert(UDSEntry::UDS_ACCESS, S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH);
......
......@@ -279,6 +279,7 @@ void NetworkSlave::listDir( const QUrl& url )
void NetworkSlave::feedEntryAsNetwork( KIO::UDSEntry* entry )
{
entry->reserve(3);
entry->fastInsert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR );
entry->fastInsert( KIO::UDSEntry::UDS_DISPLAY_NAME, i18n("Network"));
// entry->fastInsert( KIO::UDSEntry::UDS_ICON_NAME, NetworkIconName );
......@@ -288,6 +289,7 @@ void NetworkSlave::feedEntryAsNetwork( KIO::UDSEntry* entry )
void NetworkSlave::feedEntryAsDevice( KIO::UDSEntry* entry, const Mollet::NetDevice& deviceData )
{
entry->reserve(4);
entry->fastInsert( KIO::UDSEntry::UDS_NAME, deviceData.hostAddress() );
entry->fastInsert( KIO::UDSEntry::UDS_DISPLAY_NAME, deviceData.name() );
entry->fastInsert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR );
......@@ -298,6 +300,7 @@ void NetworkSlave::feedEntryAsDevice( KIO::UDSEntry* entry, const Mollet::NetDev
void NetworkSlave::feedEntryAsService( KIO::UDSEntry* entry, const Mollet::NetService& serviceData )
{
entry->reserve(7);
entry->fastInsert( KIO::UDSEntry::UDS_NAME, serviceData.name()+QLatin1Char('.')+serviceData.type() );
entry->fastInsert( KIO::UDSEntry::UDS_DISPLAY_NAME, serviceData.name() );
entry->fastInsert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFLNK );
......
......@@ -148,6 +148,7 @@ void RecentDocuments::stat(const QUrl& url)
//
QString dirName = i18n("Recent Documents");
KIO::UDSEntry uds;
uds.reserve(6);
uds.fastInsert(KIO::UDSEntry::UDS_NAME, dirName);
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, dirName);
uds.fastInsert(KIO::UDSEntry::UDS_DISPLAY_TYPE, dirName);
......
......@@ -63,6 +63,7 @@ extern "C" {
static void createFileEntry(KIO::UDSEntry& entry, const KService::Ptr& service)
{
entry.clear();
entry.reserve(9);
entry.fastInsert(KIO::UDSEntry::UDS_NAME, KIO::encodeFileName(service->desktopEntryName()));
entry.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, service->name()); // translated name
entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG);
......@@ -77,6 +78,7 @@ static void createFileEntry(KIO::UDSEntry& entry, const KService::Ptr& service)
static void createDirEntry(KIO::UDSEntry& entry, const QString& name, const QString& iconName)
{
entry.clear();
entry.reserve(6); // +1 for UDS_DISPLAY_NAME
entry.fastInsert( KIO::UDSEntry::UDS_NAME, name );
entry.fastInsert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR );
entry.fastInsert( KIO::UDSEntry::UDS_ACCESS, 0500 );
......
......@@ -411,6 +411,7 @@ bool SFTPInternal::createUDSEntry(const QString &filename, const QByteArray &pat
uint64_t size = 0U;
Q_ASSERT(entry.count() == 0);
entry.reserve(10);
sftp_attributes sb = sftp_lstat(mSftp, path.constData());
if (sb == nullptr) {
......@@ -2178,6 +2179,7 @@ Result SFTPInternal::listDir(const QUrl &url)
}
entry.clear();
entry.reserve(10);
entry.fastInsert(KIO::UDSEntry::UDS_NAME, QFile::decodeName(dirent->name));
if (dirent->type == SSH_FILEXFER_TYPE_SYMLINK) {
......
......@@ -34,6 +34,7 @@ QString DNSSDDiscovery::udsName() const
KIO::UDSEntry DNSSDDiscovery::toEntry() const
{
KIO::UDSEntry entry;
entry.reserve(6);
entry.fastInsert(KIO::UDSEntry::UDS_NAME, udsName());
entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
......
......@@ -303,6 +303,7 @@ QString WSDiscovery::udsName() const
KIO::UDSEntry WSDiscovery::toEntry() const
{
KIO::UDSEntry entry;
entry.reserve(6);
entry.fastInsert(KIO::UDSEntry::UDS_NAME, udsName());
entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment