Inspection: Variable can be made constexpr

This commit is contained in:
Urs Fleisch 2024-01-20 17:22:53 +01:00
parent 710522e6e1
commit 5d921c6325
18 changed files with 26 additions and 26 deletions

View File

@ -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)");

View File

@ -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

View File

@ -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

View File

@ -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));

View File

@ -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

View File

@ -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;

View File

@ -267,7 +267,7 @@ List<Ogg::Page *> 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.

View File

@ -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
////////////////////////////////////////////////////////////////////////////////

View File

@ -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
////////////////////////////////////////////////////////////////////////////////

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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,

View File

@ -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());

View File

@ -135,7 +135,7 @@ public:
void testAudioPropertiesADTS()
{
const std::array readStyles = {
constexpr std::array readStyles = {
MPEG::Properties::Fast,
MPEG::Properties::Average,
MPEG::Properties::Accurate

View File

@ -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;

View File

@ -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());