From 926eb88a6435bb602cbb1e14630f9df197d6e6c9 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 7 Dec 2018 14:12:31 +0100 Subject: [PATCH] Small code clean-up. --- src/Encoder_MP3.cpp | 21 ++++++++++----------- src/Encoder_MP3.h | 3 ++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Encoder_MP3.cpp b/src/Encoder_MP3.cpp index 0037ccaa..cfdf6d28 100644 --- a/src/Encoder_MP3.cpp +++ b/src/Encoder_MP3.cpp @@ -34,8 +34,15 @@ static const int g_mp3BitrateLUT[15] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 16 static const int g_lameVBRQualityLUT[11] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0, INT_MAX}; //Static -QScopedPointer MP3Encoder::m_regxLayer, MP3Encoder::m_regxVersion; QMutex MP3Encoder::m_regexMutex; +MUtils::Lazy MP3Encoder::m_regxLayer([] +{ + return new QRegExp(L1S("^Layer\\s+(1|2|3)\\b"), Qt::CaseInsensitive); +}); +MUtils::Lazy MP3Encoder::m_regxVersion([] +{ + return new QRegExp(L1S("^(Version\\s+)?(1|2|2\\.5)\\b"), Qt::CaseInsensitive); +}); /////////////////////////////////////////////////////////////////////////////// // Encoder Info @@ -281,17 +288,9 @@ bool MP3Encoder::isFormatSupported(const QString &containerType, const QString & else if (formatType.compare(mpegAudio, Qt::CaseInsensitive) == 0) { QMutexLocker lock(&m_regexMutex); - if (m_regxLayer.isNull()) + if ((*m_regxLayer).indexIn(formatProfile) >= 0) { - m_regxLayer.reset(new QRegExp(L1S("^Layer\\s+(1|2|3)\\b"), Qt::CaseInsensitive)); - } - if (m_regxLayer->indexIn(formatProfile) >= 0) - { - if (m_regxVersion.isNull()) - { - m_regxVersion.reset(new QRegExp(L1S("^(Version\\s+)?(1|2|2\\.5)\\b"), Qt::CaseInsensitive)); - } - return (m_regxVersion->indexIn(formatVersion) >= 0); + return ((*m_regxVersion).indexIn(formatVersion) >= 0); } } } diff --git a/src/Encoder_MP3.h b/src/Encoder_MP3.h index 52008ac4..fc722e5a 100644 --- a/src/Encoder_MP3.h +++ b/src/Encoder_MP3.h @@ -25,6 +25,7 @@ #include "Encoder_Abstract.h" #include +#include class MP3Encoder : public AbstractEncoder { @@ -55,7 +56,7 @@ private: int m_configChannelMode; static QMutex m_regexMutex; - static QScopedPointer m_regxLayer, m_regxVersion; + static MUtils::Lazy m_regxLayer, m_regxVersion; int clipBitrate(int bitrate); };