Inspection: Variable can be moved to inner scope

This commit is contained in:
Urs Fleisch 2024-01-20 21:25:54 +01:00
parent dfe2aa5253
commit 613355665c
11 changed files with 51 additions and 74 deletions

View File

@ -520,8 +520,7 @@ bool _taglib_complex_property_set(
while(*attrPtr) {
const TagLib_Complex_Property_Attribute *attr = *attrPtr;
String attrKey(attr->key);
TagLib_Variant_Type type = attr->value.type;
switch(type) {
switch(attr->value.type) {
case TagLib_Variant_Void:
map.insert(attrKey, Variant());
break;
@ -727,8 +726,7 @@ void taglib_picture_from_complex_property(
TagLib_Complex_Property_Attribute** attrPtr = *propPtr;
while(*attrPtr) {
TagLib_Complex_Property_Attribute *attr = *attrPtr;
TagLib_Variant_Type type = attr->value.type;
switch(type) {
switch(attr->value.type) {
case TagLib_Variant_String:
if(strcmp("mimeType", attr->key) == 0) {
picture->mimeType = attr->value.value.stringValue;
@ -779,8 +777,7 @@ void taglib_complex_property_free(
TagLib_Complex_Property_Attribute** attrPtr = *propPtr;
while(*attrPtr) {
TagLib_Complex_Property_Attribute *attr = *attrPtr;
TagLib_Variant_Type type = attr->value.type;
switch(type) {
switch(attr->value.type) {
case TagLib_Variant_String:
free(attr->value.value.stringValue);
break;

View File

@ -57,8 +57,7 @@ ItemFactory *ItemFactory::instance()
std::pair<String, Item> ItemFactory::parseItem(
const Atom *atom, const ByteVector &data) const
{
auto handlerType = handlerTypeForName(atom->name());
switch(handlerType) {
switch(handlerTypeForName(atom->name())) {
case ItemHandlerType::Unknown:
break;
case ItemHandlerType::FreeForm:
@ -98,8 +97,7 @@ ByteVector ItemFactory::renderItem(
}
else {
const ByteVector name = itemName.data(String::Latin1);
auto handlerType = handlerTypeForName(name);
switch(handlerType) {
switch(handlerTypeForName(name)) {
case ItemHandlerType::Unknown:
debug("MP4: Unknown item name \"" + name + "\"");
break;
@ -142,10 +140,9 @@ std::pair<ByteVector, Item> ItemFactory::itemFromProperty(
if(values.isEmpty()) {
return {name, values};
}
auto handlerType = name.startsWith("----")
? ItemHandlerType::FreeForm
: handlerTypeForName(name);
switch(handlerType) {
switch(name.startsWith("----")
? ItemHandlerType::FreeForm
: handlerTypeForName(name)) {
case ItemHandlerType::IntPair:
case ItemHandlerType::IntPairNoTrailing:
if(StringList parts = StringList::split(values.front(), "/");
@ -190,10 +187,9 @@ std::pair<String, StringList> ItemFactory::itemToProperty(
const ByteVector &itemName, const Item &item) const
{
if(const String key = propertyKeyForName(itemName); !key.isEmpty()) {
auto handlerType = itemName.startsWith("----")
? ItemHandlerType::FreeForm
: handlerTypeForName(itemName);
switch(handlerType) {
switch(itemName.startsWith("----")
? ItemHandlerType::FreeForm
: handlerTypeForName(itemName)) {
case ItemHandlerType::IntPair:
case ItemHandlerType::IntPairNoTrailing:
{

View File

@ -162,8 +162,7 @@ MP4::Tag::updateParents(const AtomList &path, offset_t delta, int ignore)
void
MP4::Tag::updateOffsets(offset_t delta, offset_t offset)
{
MP4::Atom *moov = d->atoms->find("moov");
if(moov) {
if(MP4::Atom *moov = d->atoms->find("moov")) {
const MP4::AtomList stco = moov->findall("stco", true);
for(const auto &atom : stco) {
if(atom->offset() > offset) {
@ -205,8 +204,7 @@ MP4::Tag::updateOffsets(offset_t delta, offset_t offset)
}
}
MP4::Atom *moof = d->atoms->find("moof");
if(moof) {
if(MP4::Atom *moof = d->atoms->find("moof")) {
const MP4::AtomList tfhd = moof->findall("tfhd", true);
for(const auto &atom : tfhd) {
if(atom->offset() > offset) {

View File

@ -303,8 +303,7 @@ void MPC::Properties::readSV7(const ByteVector &data, offset_t streamLength)
if (d->albumPeak != 0)
d->albumPeak = static_cast<int>(log10(static_cast<double>(d->albumPeak)) * 20 * 256 + .5);
bool trueGapless = (gapless >> 31) & 0x0001;
if(trueGapless) {
if((gapless >> 31) & 0x0001) {
unsigned int lastFrameSamples = (gapless >> 20) & 0x07FF;
d->sampleFrames = d->totalFrames * 1152 - lastFrameSamples;
}

View File

@ -173,9 +173,9 @@ PropertyMap TextIdentificationFrame::asProperties() const
return makeTIPLProperties();
if(frameID() == "TMCL")
return makeTMCLProperties();
PropertyMap map;
String tagName = frameIDToKey(frameID());
if(tagName.isEmpty()) {
PropertyMap map;
map.addUnsupportedData(frameID());
return map;
}

View File

@ -148,9 +148,8 @@ template <class T>
ByteVector fromNumber(T value, bool mostSignificantByteFirst)
{
const bool isBigEndian = (Utils::systemByteOrder() == Utils::BigEndian);
const bool swap = (mostSignificantByteFirst != isBigEndian);
if(swap)
if(mostSignificantByteFirst != isBigEndian)
value = Utils::byteSwap(value);
return ByteVector(reinterpret_cast<const char *>(&value), sizeof(T));

View File

@ -66,11 +66,10 @@ ByteVector zlib::decompress([[maybe_unused]] const ByteVector &data)
stream.avail_in = static_cast<uInt>(inData.size());
stream.next_in = reinterpret_cast<Bytef *>(inData.data());
const unsigned int chunkSize = 1024;
ByteVector outData;
do {
constexpr unsigned int chunkSize = 1024;
const size_t offset = outData.size();
outData.resize(outData.size() + chunkSize);

View File

@ -395,16 +395,13 @@ public:
void testRepeatedSave()
{
ScopedFileCopy copy("silence-1", ".wma");
{
ASF::File f(copy.fileName().c_str());
f.tag()->setTitle(longText(128 * 1024));
f.save();
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(297578), f.length());
f.tag()->setTitle(longText(16 * 1024));
f.save();
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(68202), f.length());
}
ASF::File f(copy.fileName().c_str());
f.tag()->setTitle(longText(128 * 1024));
f.save();
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(297578), f.length());
f.tag()->setTitle(longText(16 * 1024));
f.save();
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(68202), f.length());
}
};

View File

@ -445,24 +445,20 @@ public:
void testSaveID3v1()
{
ScopedFileCopy copy("no-tags", ".flac");
FLAC::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(!f.hasID3v1Tag());
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(4692), f.length());
ByteVector audioStream;
{
FLAC::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(!f.hasID3v1Tag());
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(4692), f.length());
f.seek(0x0100);
ByteVector audioStream = f.readBlock(4436);
f.seek(0x0100);
audioStream = f.readBlock(4436);
f.ID3v1Tag(true)->setTitle("01234 56789 ABCDE FGHIJ");
f.save();
CPPUNIT_ASSERT(f.hasID3v1Tag());
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(4820), f.length());
f.ID3v1Tag(true)->setTitle("01234 56789 ABCDE FGHIJ");
f.save();
CPPUNIT_ASSERT(f.hasID3v1Tag());
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(4820), f.length());
f.seek(0x0100);
CPPUNIT_ASSERT_EQUAL(audioStream, f.readBlock(4436));
}
f.seek(0x0100);
CPPUNIT_ASSERT_EQUAL(audioStream, f.readBlock(4436));
}
void testUpdateID3v2()

View File

@ -1107,10 +1107,8 @@ public:
PlainFile(newname.c_str()).readBlock(expectedId3v23Data.size());
CPPUNIT_ASSERT_EQUAL(expectedId3v23Data, actualId3v23Data);
}
ScopedFileCopy rareFramesCopy("rare_frames", ".mp3");
{
ScopedFileCopy rareFramesCopy("rare_frames", ".mp3");
MPEG::File f(rareFramesCopy.fileName().c_str());
f.save(MPEG::File::AllTags, File::StripOthers, ID3v2::v3);
f.seek(f.find("TCON") + 11);

View File

@ -562,23 +562,21 @@ public:
void testExtendedHeader()
{
const ScopedFileCopy copy("extended-header", ".mp3");
{
MPEG::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT(f.hasID3v2Tag());
ID3v2::Tag *tag = f.ID3v2Tag();
ID3v2::ExtendedHeader *ext = tag->extendedHeader();
CPPUNIT_ASSERT(ext);
CPPUNIT_ASSERT_EQUAL(12U, ext->size());
CPPUNIT_ASSERT_EQUAL(String("Druids"), tag->title());
CPPUNIT_ASSERT_EQUAL(String("Excelsis"), tag->artist());
CPPUNIT_ASSERT_EQUAL(String("Vo Chrieger U Drache"), tag->album());
CPPUNIT_ASSERT_EQUAL(2013U, tag->year());
CPPUNIT_ASSERT_EQUAL(String("Folk/Power Metal"), tag->genre());
CPPUNIT_ASSERT_EQUAL(3U, tag->track());
CPPUNIT_ASSERT_EQUAL(String("2013"),
f.properties().value("ORIGINALDATE").front());
}
MPEG::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(f.isValid());
CPPUNIT_ASSERT(f.hasID3v2Tag());
ID3v2::Tag *tag = f.ID3v2Tag();
ID3v2::ExtendedHeader *ext = tag->extendedHeader();
CPPUNIT_ASSERT(ext);
CPPUNIT_ASSERT_EQUAL(12U, ext->size());
CPPUNIT_ASSERT_EQUAL(String("Druids"), tag->title());
CPPUNIT_ASSERT_EQUAL(String("Excelsis"), tag->artist());
CPPUNIT_ASSERT_EQUAL(String("Vo Chrieger U Drache"), tag->album());
CPPUNIT_ASSERT_EQUAL(2013U, tag->year());
CPPUNIT_ASSERT_EQUAL(String("Folk/Power Metal"), tag->genre());
CPPUNIT_ASSERT_EQUAL(3U, tag->track());
CPPUNIT_ASSERT_EQUAL(String("2013"),
f.properties().value("ORIGINALDATE").front());
}
void testReadStyleFast()