aboutsummaryrefslogtreecommitdiffstats
path: root/taglib/asf
diff options
context:
space:
mode:
authorTsuda Kageyu <tsuda.kageyu@gmail.com>2015-11-22 20:11:08 +0900
committerTsuda Kageyu <tsuda.kageyu@gmail.com>2015-11-22 20:11:08 +0900
commit2b7d6fef4748b5bafdf4cb4f3184b73273f7b465 (patch)
tree57b13fe88fafab209844db5411801606ca4f0713 /taglib/asf
parentae633105d64067ac6562f37108c19e77be5ce0d5 (diff)
Reduce redundant ref()/deref() operations.
Diffstat (limited to 'taglib/asf')
-rw-r--r--taglib/asf/asfattribute.cpp73
-rw-r--r--taglib/asf/asfattribute.h5
-rw-r--r--taglib/asf/asfpicture.cpp23
-rw-r--r--taglib/asf/asfpicture.h5
4 files changed, 59 insertions, 47 deletions
diff --git a/taglib/asf/asfattribute.cpp b/taglib/asf/asfattribute.cpp
index 7a40bea3..a70330b0 100644
--- a/taglib/asf/asfattribute.cpp
+++ b/taglib/asf/asfattribute.cpp
@@ -58,84 +58,86 @@ public:
// public members
////////////////////////////////////////////////////////////////////////////////
-ASF::Attribute::Attribute()
+ASF::Attribute::Attribute() :
+ d(new AttributePrivate())
{
- d = new AttributePrivate;
d->type = UnicodeType;
}
-ASF::Attribute::Attribute(const ASF::Attribute &other)
- : d(other.d)
+ASF::Attribute::Attribute(const ASF::Attribute &other) :
+ d(other.d)
{
d->ref();
}
-ASF::Attribute &ASF::Attribute::operator=(const ASF::Attribute &other)
-{
- if(&other != this) {
- if(d->deref())
- delete d;
- d = other.d;
- d->ref();
- }
- return *this;
-}
-
-ASF::Attribute::~Attribute()
+ASF::Attribute::Attribute(const String &value) :
+ d(new AttributePrivate())
{
- if(d->deref())
- delete d;
-}
-
-ASF::Attribute::Attribute(const String &value)
-{
- d = new AttributePrivate;
d->type = UnicodeType;
d->stringValue = value;
}
-ASF::Attribute::Attribute(const ByteVector &value)
+ASF::Attribute::Attribute(const ByteVector &value) :
+ d(new AttributePrivate())
{
- d = new AttributePrivate;
d->type = BytesType;
d->byteVectorValue = value;
}
-ASF::Attribute::Attribute(const ASF::Picture &value)
+ASF::Attribute::Attribute(const ASF::Picture &value) :
+ d(new AttributePrivate())
{
- d = new AttributePrivate;
d->type = BytesType;
d->pictureValue = value;
}
-ASF::Attribute::Attribute(unsigned int value)
+ASF::Attribute::Attribute(unsigned int value) :
+ d(new AttributePrivate())
{
- d = new AttributePrivate;
d->type = DWordType;
d->intValue = value;
}
-ASF::Attribute::Attribute(unsigned long long value)
+ASF::Attribute::Attribute(unsigned long long value) :
+ d(new AttributePrivate())
{
- d = new AttributePrivate;
d->type = QWordType;
d->longLongValue = value;
}
-ASF::Attribute::Attribute(unsigned short value)
+ASF::Attribute::Attribute(unsigned short value) :
+ d(new AttributePrivate())
{
- d = new AttributePrivate;
d->type = WordType;
d->shortValue = value;
}
-ASF::Attribute::Attribute(bool value)
+ASF::Attribute::Attribute(bool value) :
+ d(new AttributePrivate())
{
- d = new AttributePrivate;
d->type = BoolType;
d->boolValue = value;
}
+ASF::Attribute &ASF::Attribute::operator=(const ASF::Attribute &other)
+{
+ Attribute(other).swap(*this);
+ return *this;
+}
+
+void ASF::Attribute::swap(Attribute &other)
+{
+ using std::swap;
+
+ swap(d, other.d);
+}
+
+ASF::Attribute::~Attribute()
+{
+ if(d->deref())
+ delete d;
+}
+
ASF::Attribute::AttributeTypes ASF::Attribute::type() const
{
return d->type;
@@ -351,4 +353,3 @@ void ASF::Attribute::setStream(int value)
{
d->stream = value;
}
-
diff --git a/taglib/asf/asfattribute.h b/taglib/asf/asfattribute.h
index 54eb0c7d..64979216 100644
--- a/taglib/asf/asfattribute.h
+++ b/taglib/asf/asfattribute.h
@@ -116,6 +116,11 @@ namespace TagLib
ASF::Attribute &operator=(const Attribute &other);
/*!
+ * Exchanges the content of the Attribute by the content of \a other.
+ */
+ void swap(Attribute &other);
+
+ /*!
* Destroys the attribute.
*/
virtual ~Attribute();
diff --git a/taglib/asf/asfpicture.cpp b/taglib/asf/asfpicture.cpp
index f772052f..5a3e4411 100644
--- a/taglib/asf/asfpicture.cpp
+++ b/taglib/asf/asfpicture.cpp
@@ -48,14 +48,14 @@ public:
// Picture class members
////////////////////////////////////////////////////////////////////////////////
-ASF::Picture::Picture()
+ASF::Picture::Picture() :
+ d(new PicturePrivate())
{
- d = new PicturePrivate();
d->valid = true;
}
-ASF::Picture::Picture(const Picture& other)
- : d(other.d)
+ASF::Picture::Picture(const Picture& other) :
+ d(other.d)
{
d->ref();
}
@@ -120,15 +120,17 @@ int ASF::Picture::dataSize() const
ASF::Picture& ASF::Picture::operator=(const ASF::Picture& other)
{
- if(other.d != d) {
- if(d->deref())
- delete d;
- d = other.d;
- d->ref();
- }
+ Picture(other).swap(*this);
return *this;
}
+void ASF::Picture::swap(Picture &other)
+{
+ using std::swap;
+
+ swap(d, other.d);
+}
+
ByteVector ASF::Picture::render() const
{
if(!isValid())
@@ -179,4 +181,3 @@ ASF::Picture ASF::Picture::fromInvalid()
ret.d->valid = false;
return ret;
}
-
diff --git a/taglib/asf/asfpicture.h b/taglib/asf/asfpicture.h
index b510c35f..17233ba9 100644
--- a/taglib/asf/asfpicture.h
+++ b/taglib/asf/asfpicture.h
@@ -118,6 +118,11 @@ namespace TagLib
Picture& operator=(const Picture& other);
/*!
+ * Exchanges the content of the Picture by the content of \a other.
+ */
+ void swap(Picture &other);
+
+ /*!
* Returns true if Picture stores valid picture
*/
bool isValid() const;