Use QHash<K,V> instead of QMap<K,V> when K is a pointer type

Changes various internal usages of QMap when the key is a pointer type.
Being ordered by the pointer value itself, it makes very little sense
to use QMap<K*, V> (esp. in cases where the key is actually allocated
on the heap).

The usages have been found with the following script:

 #!/usr/bin/perl

 use strict;
 use warnings;
 use Regexp::Common;
 use File::Find;
 use feature ':5.10';

 my $container = qr/(?:QMap)/;

 sub process {
     return unless (-f and -r and /(\.c|\.cpp|\.h|\.txt)$/);
     open my $fh, "<", $_ or die "Cannot open $_: $!";
     while (my $line = <$fh>) {
         chomp $line;
         while ($line =~ /($container\s*$RE{balanced}{-parens=>"<>"})/g) {
             my $tmp = $1;
             $tmp =~ s/\s+//g;
             say "$_:$.: $line" if $tmp =~ /^$container\s*<[^,]+\*,/;
         }
     }
     close $fh;
 }

 find( { no_chdir => 1, wanted => \&process }, @ARGV );

Change-Id: Idd9819c3f4c48f98ef92831d5e8e5ac0fa42283c
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Giuseppe D'Angelo 2012-03-01 23:47:36 +00:00 committed by Qt by Nokia
parent 95d83cb1b6
commit 7ae38c49b7
11 changed files with 23 additions and 23 deletions

View File

@ -783,7 +783,7 @@ static inline void _q_adjustRect(QRect *rect)
class QGraphicsItemCustomDataStore
{
public:
QMap<const QGraphicsItem *, QMap<int, QVariant> > data;
QHash<const QGraphicsItem *, QMap<int, QVariant> > data;
};
Q_GLOBAL_STATIC(QGraphicsItemCustomDataStore, qt_dataStore)
@ -1379,7 +1379,7 @@ void QGraphicsItemCache::purge()
{
QPixmapCache::remove(key);
key = QPixmapCache::Key();
QMutableMapIterator<QPaintDevice *, DeviceData> it(deviceData);
QMutableHashIterator<QPaintDevice *, DeviceData> it(deviceData);
while (it.hasNext()) {
DeviceData &data = it.next().value();
QPixmapCache::remove(data.key);
@ -7124,7 +7124,7 @@ void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if ((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable)) {
// Determine the list of items that need to be moved.
QList<QGraphicsItem *> selectedItems;
QMap<QGraphicsItem *, QPointF> initialPositions;
QHash<QGraphicsItem *, QPointF> initialPositions;
if (d_ptr->scene) {
selectedItems = d_ptr->scene->selectedItems();
initialPositions = d_ptr->scene->d_func()->movingItemsInitialPositions;

View File

@ -145,7 +145,7 @@ public:
QPoint cacheIndent;
QPixmapCache::Key key;
};
QMap<QPaintDevice *, DeviceData> deviceData;
QHash<QPaintDevice *, DeviceData> deviceData;
// List of logical exposed rects
QVector<QRectF> exposed;
@ -508,7 +508,7 @@ public:
QRectF childrenBoundingRect;
QRectF needsRepaint;
QMap<QWidget *, QRect> paintedViewBoundingRects;
QHash<QWidget *, QRect> paintedViewBoundingRects;
QPointF pos;
qreal z;
qreal opacity;

View File

@ -128,7 +128,7 @@ public:
QVector<QGraphicsItem *> unpolishedItems;
QList<QGraphicsItem *> topLevelItems;
QMap<QGraphicsItem *, QPointF> movingItemsInitialPositions;
QHash<QGraphicsItem *, QPointF> movingItemsInitialPositions;
void registerTopLevelItem(QGraphicsItem *item);
void unregisterTopLevelItem(QGraphicsItem *item);
void _q_updateLater();

View File

@ -222,7 +222,7 @@ public:
}
private:
QMap<const QGraphicsWidget *, QStyle *> styles;
QHash<const QGraphicsWidget *, QStyle *> styles;
mutable QMutex mutex;
};
Q_GLOBAL_STATIC(QGraphicsWidgetStyles, widgetStyles)

View File

@ -313,7 +313,7 @@ public:
QPointer<QWSManager> last_manager;
QWSServerCleaner qwsServerCleaner;
# ifndef QT_NO_DIRECTPAINTER
QMap<WId, QDirectPainter *> *directPainters;
QHash<WId, QDirectPainter *> *directPainters;
# endif
QRect maxWindowRect(const QScreen *screen) const { return maxWindowRects[screen]; }
void setMaxWindowRect(const QScreen *screen, int screenNo, const QRect &rect);
@ -393,7 +393,7 @@ public:
private:
#ifdef Q_WS_QWS
QMap<const QScreen*, QRect> maxWindowRects;
QHash<const QScreen*, QRect> maxWindowRects;
#endif
static QApplicationPrivate *self;

View File

@ -541,8 +541,8 @@ bool QGestureManager::filterEvent(QObject *receiver, QEvent *event)
}
void QGestureManager::getGestureTargets(const QSet<QGesture*> &gestures,
QMap<QWidget *, QList<QGesture *> > *conflicts,
QMap<QWidget *, QList<QGesture *> > *normal)
QHash<QWidget *, QList<QGesture *> > *conflicts,
QHash<QWidget *, QList<QGesture *> > *normal)
{
typedef QHash<Qt::GestureType, QHash<QWidget *, QGesture *> > GestureByTypes;
GestureByTypes gestureByTypes;
@ -588,7 +588,7 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures,
if (gestures.isEmpty())
return;
typedef QMap<QWidget *, QList<QGesture *> > GesturesPerWidget;
typedef QHash<QWidget *, QList<QGesture *> > GesturesPerWidget;
GesturesPerWidget conflictedGestures;
GesturesPerWidget normalStartedGestures;

View File

@ -138,8 +138,8 @@ private:
void deliverEvents(const QSet<QGesture *> &gestures,
QSet<QGesture *> *undeliveredGestures);
void getGestureTargets(const QSet<QGesture*> &gestures,
QMap<QWidget *, QList<QGesture *> > *conflicts,
QMap<QWidget *, QList<QGesture *> > *normal);
QHash<QWidget *, QList<QGesture *> > *conflicts,
QHash<QWidget *, QList<QGesture *> > *normal);
void cancelGesturesForChildren(QGesture *originatingGesture);
};

View File

@ -897,7 +897,7 @@ extern QStringList qt_make_filter_list(const QString &filter);
void QGtkStylePrivate::setupGtkFileChooser(GtkWidget* gtkFileChooser, QWidget *parent,
const QString &dir, const QString &filter, QString *selectedFilter,
QFileDialog::Options options, bool isSaveDialog,
QMap<GtkFileFilter *, QString> *filterMap)
QHash<GtkFileFilter *, QString> *filterMap)
{
g_object_set(gtkFileChooser, "do-overwrite-confirmation", gboolean(!(options & QFileDialog::DontConfirmOverwrite)), NULL);
g_object_set(gtkFileChooser, "local_only", gboolean(true), NULL);
@ -969,7 +969,7 @@ void QGtkStylePrivate::setupGtkFileChooser(GtkWidget* gtkFileChooser, QWidget *p
QString QGtkStylePrivate::openFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter,
QString *selectedFilter, QFileDialog::Options options)
{
QMap<GtkFileFilter *, QString> filterMap;
QHash<GtkFileFilter *, QString> filterMap;
GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption),
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
@ -1003,7 +1003,7 @@ QString QGtkStylePrivate::openFilename(QWidget *parent, const QString &caption,
QString QGtkStylePrivate::openDirectory(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options)
{
QMap<GtkFileFilter *, QString> filterMap;
QHash<GtkFileFilter *, QString> filterMap;
GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption),
NULL,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
@ -1033,7 +1033,7 @@ QStringList QGtkStylePrivate::openFilenames(QWidget *parent, const QString &capt
QString *selectedFilter, QFileDialog::Options options)
{
QStringList filenames;
QMap<GtkFileFilter *, QString> filterMap;
QHash<GtkFileFilter *, QString> filterMap;
GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption),
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
@ -1068,7 +1068,7 @@ QStringList QGtkStylePrivate::openFilenames(QWidget *parent, const QString &capt
QString QGtkStylePrivate::saveFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter,
QString *selectedFilter, QFileDialog::Options options)
{
QMap<GtkFileFilter *, QString> filterMap;
QHash<GtkFileFilter *, QString> filterMap;
GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption),
NULL,
GTK_FILE_CHOOSER_ACTION_SAVE,

View File

@ -344,7 +344,7 @@ public:
static void setupGtkFileChooser(GtkWidget* gtkFileChooser, QWidget *parent,
const QString &dir, const QString &filter, QString *selectedFilter,
QFileDialog::Options options, bool isSaveDialog = false,
QMap<GtkFileFilter *, QString> *filterMap = 0);
QHash<GtkFileFilter *, QString> *filterMap = 0);
static QString openFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter,
QString *selectedFilter, QFileDialog::Options options);

View File

@ -190,7 +190,7 @@ public:
void detectCheckedButton();
void notifyChecked(QAbstractButton *button);
bool exclusive;
QMap<QAbstractButton*, int> mapping;
QHash<QAbstractButton*, int> mapping;
};
QButtonGroup::QButtonGroup(QObject *parent)

View File

@ -54,7 +54,7 @@
//
#include <qobject.h>
#include <qmap.h>
#include <qhash.h>
QT_BEGIN_NAMESPACE
@ -79,7 +79,7 @@ private Q_SLOTS:
#endif
private:
typedef QMap<QWidget*, QPropertyAnimation*> AnimationMap;
typedef QHash<QWidget*, QPropertyAnimation*> AnimationMap;
AnimationMap m_animation_map;
QMainWindowLayout *m_mainWindowLayout;
};