[patch] pass-by-reference

Erik Hovland erik at hovland.org
Fri Dec 1 22:52:08 UTC 2006


If an object is large it is much quicker to pass it by reference.
MetaBundle qualifies as large. So this patch addresses its use and
attempts to make it pass-by-reference in a few places. Annotation in
patch.

E

-- 
Erik Hovland
mail: erik AT hovland DOT org
web: http://hovland.org/
PGP/GPG public key available on request
-------------- next part --------------
This patch changes certain methods to use pass by ref instead of
pass by value.

This can provide a little performance improvement to certain parts of
the system since large objects are not being copied
as often.

The only thing strange about this patch is that to be able to
pass-by-ref a few member functions had to have their const-ness dealt with
because the dcop handler gives a const reference. But otherwise, the patch
is straight forward. I would only expect a marginal perf boost since
MetaBundle is not that large and in this case it is only involved in
album art processing. But hey, I'll take performance wherever I can get it.

Signed-off-by: Erik Hovland <erik at hovland.org>

---

 src/collectiondb.cpp |    6 +++---
 src/collectiondb.h   |    6 +++---
 src/metabundle.cpp   |    4 ++--
 src/metabundle.h     |    4 ++--
 src/tagdialog.cpp    |    2 +-
 src/tagdialog.h      |    2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/collectiondb.cpp b/src/collectiondb.cpp
index 227fdc5..3648507 100644
--- a/src/collectiondb.cpp
+++ b/src/collectiondb.cpp
@@ -1997,7 +1997,7 @@ CollectionDB::albumImage( const uint art
 
 
 QString
-CollectionDB::albumImage( MetaBundle trackInformation, bool withShadow, uint width, bool* embedded )
+CollectionDB::albumImage( const MetaBundle &trackInformation, bool withShadow, uint width, bool* embedded )
 {
     QString s;
     if( width == 1 )
@@ -2227,7 +2227,7 @@ CollectionDB::findEmbeddedImage( const Q
 
 
 QString
-CollectionDB::findMetaBundleImage( MetaBundle trackInformation, uint width )
+CollectionDB::findMetaBundleImage( const MetaBundle& trackInformation, uint width )
 {
     int deviceid = MountPointManager::instance()->getIdForUrl( trackInformation.url() );
     QString rpath = MountPointManager::instance()->getRelativePath( deviceid, trackInformation.url().path() );
@@ -5750,7 +5750,7 @@ CollectionDB::loadHashFile( const QCStri
 
 
 bool
-CollectionDB::extractEmbeddedImage( MetaBundle &trackInformation, QCString& hash )
+CollectionDB::extractEmbeddedImage( const MetaBundle &trackInformation, QCString& hash )
 {
     //debug() << "extractEmbeddedImage: " << hash << " - " << trackInformation.url().path() << endl;
 
diff --git a/src/collectiondb.h b/src/collectiondb.h
index 3cb1c10..2d907ab 100644
--- a/src/collectiondb.h
+++ b/src/collectiondb.h
@@ -434,7 +434,7 @@ class LIBAMAROK_EXPORT CollectionDB : pu
         QString findAmazonImage( const QString &artist, const QString &album, const uint width = 1 );
         QString findDirectoryImage( const QString& artist, const QString& album, uint width = 0 );
         QString findEmbeddedImage( const QString& artist, const QString& album, uint width = 1 );
-        QString findMetaBundleImage( MetaBundle trackInformation, const uint = 1 );
+        QString findMetaBundleImage( const MetaBundle &trackInformation, const uint = 1 );
 
         /// ensure the sql only return urls to tracks for efficiency
         static QPixmap createDragPixmapFromSQL( const QString &sql, QString textOverRide=QString::null );
@@ -455,7 +455,7 @@ class LIBAMAROK_EXPORT CollectionDB : pu
          * @param width the size of the image. 0 == full size, 1 == preview size
          * @param embedded if not NULL, sets a bool indicating whether the path is an embedded image
          */
-        QString albumImage( MetaBundle trackInformation, const bool withShadow = false, uint width = 1, bool* embedded = 0 );
+        QString albumImage( const MetaBundle &trackInformation, const bool withShadow = false, uint width = 1, bool* embedded = 0 );
         QString albumImage( const uint artist_id, const uint album_id, const bool withShadow = false, uint width = 1, bool* embedded = 0 );
         QString albumImage( const QString &artist, const QString &album, const bool withShadow = false, uint width = 1, bool* embedded = 0 );
 
@@ -559,7 +559,7 @@ class LIBAMAROK_EXPORT CollectionDB : pu
 
         // helpers for embedded images
         QString loadHashFile( const QCString& hash, uint width );
-        bool extractEmbeddedImage( MetaBundle &trackInformation, QCString& hash );
+        bool extractEmbeddedImage( const MetaBundle &trackInformation, QCString& hash );
 
         //general management methods
         void createStatsTable();
diff --git a/src/metabundle.cpp b/src/metabundle.cpp
index 9d77cb8..a005d1c 100644
--- a/src/metabundle.cpp
+++ b/src/metabundle.cpp
@@ -467,7 +467,7 @@ MetaBundle::init( const KFileMetaInfo& i
 }
 
 void
-MetaBundle::embeddedImages( MetaBundle::EmbeddedImageList& images )
+MetaBundle::embeddedImages( MetaBundle::EmbeddedImageList& images ) const
 {
     if ( isFile() )
     {
@@ -1371,7 +1371,7 @@ MetaBundle::setLastFmBundle( const LastF
    *m_lastFmBundle = last;
 }
 
-void MetaBundle::loadImagesFromTag( const TagLib::ID3v2::Tag &tag, EmbeddedImageList& images )
+void MetaBundle::loadImagesFromTag( const TagLib::ID3v2::Tag &tag, EmbeddedImageList& images ) const
 {
     TagLib::ID3v2::FrameList l = tag.frameListMap()[ "APIC" ];
     foreachType( TagLib::ID3v2::FrameList, l ) {
diff --git a/src/metabundle.h b/src/metabundle.h
index 52de8dd..f0ff47c 100644
--- a/src/metabundle.h
+++ b/src/metabundle.h
@@ -162,7 +162,7 @@ public:
     bool audioPropertiesUndetermined() const;
 
     /** The embedded artwork in the file (loaded from file into images variable, unmodified if no images present/loadable) */
-    void embeddedImages(EmbeddedImageList &images);
+    void embeddedImages(EmbeddedImageList &images) const;
 
     /** If you want Accurate reading say so. If EmbeddedImageList != NULL, embedded art is loaded into it */
     void readTags( TagLib::AudioProperties::ReadStyle = TagLib::AudioProperties::Fast, EmbeddedImageList* images = 0 );
@@ -428,7 +428,7 @@ private:
 
     void setExtendedTag( TagLib::File *file, int tag, const QString value );
 
-    void loadImagesFromTag( const TagLib::ID3v2::Tag &tag, EmbeddedImageList& images );
+    void loadImagesFromTag( const TagLib::ID3v2::Tag &tag, EmbeddedImageList& images ) const;
 
     int getRand();
 };
diff --git a/src/tagdialog.cpp b/src/tagdialog.cpp
index e33114f..2ea8316 100644
--- a/src/tagdialog.cpp
+++ b/src/tagdialog.cpp
@@ -1412,7 +1412,7 @@ TagDialog::openURLRequest(const KURL &ur
 }
 
 bool
-TagDialog::writeTag( MetaBundle mb, bool updateCB )
+TagDialog::writeTag( MetaBundle &mb, bool updateCB )
 {
     QCString path = QFile::encodeName( mb.url().path() );
     if ( !TagLib::File::isWritable( path ) ) {
diff --git a/src/tagdialog.h b/src/tagdialog.h
index 27413d1..80c806a 100644
--- a/src/tagdialog.h
+++ b/src/tagdialog.h
@@ -95,7 +95,7 @@ class TagDialog : public TagDialogBase
         QStringList labelsForURL( const KURL &url );
         QStringList getCommonLabels();
         void saveTags();
-        bool writeTag( MetaBundle mb, bool updateCB=true );
+        bool writeTag( MetaBundle &mb, bool updateCB=true );
         const QString unknownSafe( QString );
         const QStringList statisticsData();
         void applyToAllTracks();


More information about the Amarok mailing list