From 5d921c6325569d24e1ecd646757b17e4405d2795 Mon Sep 17 00:00:00 2001 From: Urs Fleisch Date: Sat, 20 Jan 2024 17:22:53 +0100 Subject: [PATCH] Inspection: Variable can be made constexpr --- taglib/ape/apetag.cpp | 4 ++-- taglib/flac/flacfile.cpp | 6 +++--- taglib/mpc/mpcproperties.h | 2 +- taglib/mpeg/id3v2/frames/privateframe.cpp | 2 +- taglib/mpeg/id3v2/id3v2tag.cpp | 4 ++-- taglib/mpeg/mpegheader.cpp | 2 +- taglib/ogg/oggpage.cpp | 2 +- taglib/ogg/vorbis/vorbisfile.cpp | 2 +- taglib/ogg/vorbis/vorbisproperties.cpp | 2 +- taglib/toolkit/tbytevector.cpp | 4 ++-- taglib/trueaudio/trueaudioproperties.h | 2 +- taglib/wavpack/wavpackproperties.h | 2 +- tests/test_bytevector.cpp | 2 +- tests/test_flac.cpp | 2 +- tests/test_mp4.cpp | 6 +++--- tests/test_mpeg.cpp | 2 +- tests/test_string.cpp | 4 ++-- tests/test_wav.cpp | 2 +- 18 files changed, 26 insertions(+), 26 deletions(-) diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index bd7c62ab..6f7b16f2 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -47,8 +47,8 @@ using namespace APE; namespace { - const unsigned int MinKeyLength = 2; - const unsigned int MaxKeyLength = 255; + constexpr unsigned int MinKeyLength = 2; + constexpr unsigned int MaxKeyLength = 255; const String FRONT_COVER("COVER ART (FRONT)"); const String BACK_COVER("COVER ART (BACK)"); diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index 5387257d..3812e4a2 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -45,10 +45,10 @@ namespace { enum { FlacXiphIndex = 0, FlacID3v2Index = 1, FlacID3v1Index = 2 }; - const long MinPaddingLength = 4096; - const long MaxPaddingLegnth = 1024 * 1024; + constexpr long MinPaddingLength = 4096; + constexpr long MaxPaddingLegnth = 1024 * 1024; - const char LastBlockFlag = '\x80'; + constexpr char LastBlockFlag = '\x80'; } // namespace class FLAC::File::FilePrivate diff --git a/taglib/mpc/mpcproperties.h b/taglib/mpc/mpcproperties.h index dd7e15d4..ca343da0 100644 --- a/taglib/mpc/mpcproperties.h +++ b/taglib/mpc/mpcproperties.h @@ -36,7 +36,7 @@ namespace TagLib { class File; - static const unsigned int HeaderSize = 8 * 7; + static constexpr unsigned int HeaderSize = 8 * 7; //! An implementation of audio property reading for MPC diff --git a/taglib/mpeg/id3v2/frames/privateframe.cpp b/taglib/mpeg/id3v2/frames/privateframe.cpp index 3f56c378..b8ccb90b 100644 --- a/taglib/mpeg/id3v2/frames/privateframe.cpp +++ b/taglib/mpeg/id3v2/frames/privateframe.cpp @@ -98,7 +98,7 @@ void PrivateFrame::parseFields(const ByteVector &data) // Owner identifier is assumed to be Latin1 - const int byteAlign = 1; + constexpr int byteAlign = 1; const int endOfOwner = data.find(textDelimiter(String::Latin1), 0, byteAlign); d->owner = String(data.mid(0, endOfOwner)); diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index d3d02c3d..0bb4f5c4 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -54,8 +54,8 @@ namespace const ID3v2::Latin1StringHandler defaultStringHandler; const ID3v2::Latin1StringHandler *stringHandler = &defaultStringHandler; - const long MinPaddingSize = 1024; - const long MaxPaddingSize = 1024 * 1024; + constexpr long MinPaddingSize = 1024; + constexpr long MaxPaddingSize = 1024 * 1024; } // namespace class ID3v2::Tag::TagPrivate diff --git a/taglib/mpeg/mpegheader.cpp b/taglib/mpeg/mpegheader.cpp index 43b67c18..84d85e78 100644 --- a/taglib/mpeg/mpegheader.cpp +++ b/taglib/mpeg/mpegheader.cpp @@ -349,7 +349,7 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength) if(nextData.size() < 4) return; - const unsigned int HeaderMask = 0xfffe0c00; + constexpr unsigned int HeaderMask = 0xfffe0c00; const unsigned int header = data.toUInt(0, true) & HeaderMask; const unsigned int nextHeader = nextData.toUInt(0, true) & HeaderMask; diff --git a/taglib/ogg/oggpage.cpp b/taglib/ogg/oggpage.cpp index cd54014f..9e2819d4 100644 --- a/taglib/ogg/oggpage.cpp +++ b/taglib/ogg/oggpage.cpp @@ -267,7 +267,7 @@ List Ogg::Page::paginate(const ByteVectorList &packets, // SplitSize must be a multiple of 255 in order to get the lacing values right // create pages of about 8KB each - static const unsigned int SplitSize = 32 * 255; + static constexpr unsigned int SplitSize = 32 * 255; // Force repagination if the segment table will exceed the size limit. diff --git a/taglib/ogg/vorbis/vorbisfile.cpp b/taglib/ogg/vorbis/vorbisfile.cpp index 57276a27..69cd6f4f 100644 --- a/taglib/ogg/vorbis/vorbisfile.cpp +++ b/taglib/ogg/vorbis/vorbisfile.cpp @@ -43,7 +43,7 @@ namespace TagLib { * Vorbis headers can be found with one type ID byte and the string "vorbis" in * an Ogg stream. 0x03 indicates the comment header. */ - static const char vorbisCommentHeaderID[] = { 0x03, 'v', 'o', 'r', 'b', 'i', 's', 0 }; + static constexpr char vorbisCommentHeaderID[] = { 0x03, 'v', 'o', 'r', 'b', 'i', 's', 0 }; } // namespace TagLib //////////////////////////////////////////////////////////////////////////////// diff --git a/taglib/ogg/vorbis/vorbisproperties.cpp b/taglib/ogg/vorbis/vorbisproperties.cpp index cbafc236..4ba6f84d 100644 --- a/taglib/ogg/vorbis/vorbisproperties.cpp +++ b/taglib/ogg/vorbis/vorbisproperties.cpp @@ -50,7 +50,7 @@ namespace TagLib { * Vorbis headers can be found with one type ID byte and the string "vorbis" in * an Ogg stream. 0x01 indicates the setup header. */ - static const char vorbisSetupHeaderID[] = { 0x01, 'v', 'o', 'r', 'b', 'i', 's', 0 }; + static constexpr char vorbisSetupHeaderID[] = { 0x01, 'v', 'o', 'r', 'b', 'i', 's', 0 }; } // namespace TagLib //////////////////////////////////////////////////////////////////////////////// diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index f65cfff6..14fbc7c7 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -827,7 +827,7 @@ void ByteVector::swap(ByteVector &v) noexcept ByteVector ByteVector::toHex() const { - static const char hexTable[17] = "0123456789abcdef"; + static constexpr char hexTable[17] = "0123456789abcdef"; ByteVector encoded(size() * 2); char *p = encoded.data(); @@ -925,7 +925,7 @@ ByteVector ByteVector::fromBase64(const ByteVector & input) ByteVector ByteVector::toBase64() const { - static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + static constexpr char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; if(!isEmpty()) { unsigned int len = size(); ByteVector output(4 * ((len - 1) / 3 + 1)); // note roundup diff --git a/taglib/trueaudio/trueaudioproperties.h b/taglib/trueaudio/trueaudioproperties.h index ba98518f..14f85bf2 100644 --- a/taglib/trueaudio/trueaudioproperties.h +++ b/taglib/trueaudio/trueaudioproperties.h @@ -37,7 +37,7 @@ namespace TagLib { namespace TrueAudio { - static const unsigned int HeaderSize = 18; + static constexpr unsigned int HeaderSize = 18; //! An implementation of audio property reading for TrueAudio diff --git a/taglib/wavpack/wavpackproperties.h b/taglib/wavpack/wavpackproperties.h index 7d03ee43..14f1a808 100644 --- a/taglib/wavpack/wavpackproperties.h +++ b/taglib/wavpack/wavpackproperties.h @@ -40,7 +40,7 @@ namespace TagLib { class File; - static const unsigned int HeaderSize = 32; + static constexpr unsigned int HeaderSize = 32; //! An implementation of audio property reading for WavPack diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index 0410fc53..44f1211c 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -240,7 +240,7 @@ public: void testFloatingPointConversion() { - const double Tolerance = 1.0e-7; + constexpr double Tolerance = 1.0e-7; const ByteVector pi32le("\xdb\x0f\x49\x40", 4); CPPUNIT_ASSERT(std::abs(pi32le.toFloat32LE(0) - M_PI) < Tolerance); diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp index 3add7515..d5fd6bf3 100644 --- a/tests/test_flac.cpp +++ b/tests/test_flac.cpp @@ -648,7 +648,7 @@ public: CPPUNIT_ASSERT_EQUAL(String("Title"), f.xiphComment(false)->title()); } - const unsigned char expectedHeadData[] = { + constexpr unsigned char expectedHeadData[] = { 'f', 'L', 'a', 'C', 0x00, 0x00, 0x00, 0x22, 0x12, 0x00, 0x12, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x10, 0x0a, 0xc4, 0x42, 0xf0, 0x00, 0x02, 0x7a, 0xc0, 0xa1, 0xb1, 0x41, 0xf7, 0x66, 0xe9, 0x84, 0x9a, 0xc3, 0xdb, diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp index 47c88c6d..359dab4c 100644 --- a/tests/test_mp4.cpp +++ b/tests/test_mp4.cpp @@ -636,9 +636,9 @@ public: const String testComment("Comment"); const String testGenre("Genre"); const String nullString; - const unsigned int testYear = 2020; - const unsigned int testTrack = 1; - const unsigned int zeroUInt = 0; + constexpr unsigned int testYear = 2020; + constexpr unsigned int testTrack = 1; + constexpr unsigned int zeroUInt = 0; tag->setTitle(testTitle); CPPUNIT_ASSERT_EQUAL(testTitle, tag->title()); diff --git a/tests/test_mpeg.cpp b/tests/test_mpeg.cpp index 54d833f8..3f8c7ad7 100644 --- a/tests/test_mpeg.cpp +++ b/tests/test_mpeg.cpp @@ -135,7 +135,7 @@ public: void testAudioPropertiesADTS() { - const std::array readStyles = { + constexpr std::array readStyles = { MPEG::Properties::Fast, MPEG::Properties::Average, MPEG::Properties::Accurate diff --git a/tests/test_string.cpp b/tests/test_string.cpp index c0a947d4..07caa62c 100644 --- a/tests/test_string.cpp +++ b/tests/test_string.cpp @@ -96,8 +96,8 @@ public: String unicode3(L"\u65E5\u672C\u8A9E"); CPPUNIT_ASSERT(*(unicode3.toCWString() + 1) == L'\u672C'); - const wchar_t wcSystemOrder[] = {L'\u65E5', L'\u672C', L'\u8A9E', 0}; - const wchar_t wcSwappedOrder[] = {L'\uE565', L'\u2C67', L'\u9E8A', 0}; + constexpr wchar_t wcSystemOrder[] = {L'\u65E5', L'\u672C', L'\u8A9E', 0}; + constexpr wchar_t wcSwappedOrder[] = {L'\uE565', L'\u2C67', L'\u9E8A', 0}; const std::wstring wsSystemOrder = L"\u65e5\u672c\u8a9e"; const std::wstring wsSwappedOrder = L"\ue565\u2c67\u9e8a"; const bool isLe = Utils::systemByteOrder() == Utils::LittleEndian; diff --git a/tests/test_wav.cpp b/tests/test_wav.cpp index 8e11afc2..5491dd67 100644 --- a/tests/test_wav.cpp +++ b/tests/test_wav.cpp @@ -316,7 +316,7 @@ public: { FileStream stream(copy.fileName().c_str()); stream.seek(0, IOStream::End); - const char garbage[] = "12345678"; + constexpr char garbage[] = "12345678"; stream.writeBlock(ByteVector(garbage, sizeof(garbage) - 1)); stream.seek(0); contentsBeforeModification = stream.readBlock(stream.length());