From a35cbdc4a9e1e40258fcb25c6c0b4759d5942037 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Fri, 15 Jan 2016 11:32:16 +0300 Subject: [PATCH] Fix unchecked dynamic_cast Replace some unnecessary (and slow) dynamic_cast with static_cast. --- src/gui/torrentcontentmodel.cpp | 9 ++++++--- src/gui/transferlistsortmodel.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index ac4269048..8faf800bd 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -167,9 +167,12 @@ TorrentContentModelItem::ItemType TorrentContentModel::itemType(const QModelInde int TorrentContentModel::getFileIndex(const QModelIndex& index) { - TorrentContentModelFile* item = dynamic_cast(static_cast(index.internalPointer())); - Q_ASSERT(item); - return item->fileIndex(); + TorrentContentModelItem *item = static_cast(index.internalPointer()); + if (item->itemType() == TorrentContentModelItem::FileType) + return static_cast(item)->fileIndex(); + + Q_ASSERT(item->itemType() == TorrentContentModelItem::FileType); + return -1; } QVariant TorrentContentModel::data(const QModelIndex& index, int role) const diff --git a/src/gui/transferlistsortmodel.cpp b/src/gui/transferlistsortmodel.cpp index 658563f37..4e7f97c92 100644 --- a/src/gui/transferlistsortmodel.cpp +++ b/src/gui/transferlistsortmodel.cpp @@ -191,7 +191,7 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex bool TransferListSortModel::lowerPositionThan(const QModelIndex &left, const QModelIndex &right) const { - const TorrentModel *model = dynamic_cast(sourceModel()); + const TorrentModel *model = static_cast(sourceModel()); // Sort according to TR_PRIORITY const int queueL = model->data(model->index(left.row(), TorrentModel::TR_PRIORITY)).toInt();