From 2971891c69b4edc730ec13398c6fe36af7e2eb05 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Thu, 21 Aug 2014 16:35:35 +0900 Subject: [PATCH] Reduce useless detach operations by making some non-const iterators const. --- bindings/c/tag_c.cpp | 2 +- examples/tagwriter.cpp | 4 ++-- taglib/ape/apetag.cpp | 2 +- taglib/mod/modtag.cpp | 2 +- taglib/mp4/mp4tag.cpp | 6 +++--- taglib/mpeg/id3v2/frames/chapterframe.cpp | 6 +++--- taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp | 6 +++--- .../mpeg/id3v2/frames/textidentificationframe.cpp | 6 +++--- taglib/mpeg/id3v2/frames/urllinkframe.cpp | 2 +- taglib/mpeg/id3v2/id3v2framefactory.cpp | 14 +++++++------- taglib/mpeg/id3v2/id3v2header.cpp | 2 +- taglib/mpeg/id3v2/id3v2tag.cpp | 6 +++--- taglib/ogg/oggfile.cpp | 2 +- taglib/tag.cpp | 2 +- taglib/toolkit/tpropertymap.cpp | 12 ++++++------ taglib/xm/xmfile.cpp | 2 +- 16 files changed, 38 insertions(+), 38 deletions(-) diff --git a/bindings/c/tag_c.cpp b/bindings/c/tag_c.cpp index 2ae8c7dd..d2567fef 100644 --- a/bindings/c/tag_c.cpp +++ b/bindings/c/tag_c.cpp @@ -233,7 +233,7 @@ void taglib_tag_free_strings() if(!stringManagementEnabled) return; - for(List::Iterator it = strings.begin(); it != strings.end(); ++it) + for(List::ConstIterator it = strings.begin(); it != strings.end(); ++it) free(*it); strings.clear(); } diff --git a/examples/tagwriter.cpp b/examples/tagwriter.cpp index 63163fbe..f2896d76 100644 --- a/examples/tagwriter.cpp +++ b/examples/tagwriter.cpp @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) char field = argv[i][1]; TagLib::String value = argv[i + 1]; - TagLib::List::Iterator it; + TagLib::List::ConstIterator it; for(it = fileList.begin(); it != fileList.end(); ++it) { TagLib::Tag *t = (*it).tag(); @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) usage(); } - TagLib::List::Iterator it; + TagLib::List::ConstIterator it; for(it = fileList.begin(); it != fileList.end(); ++it) (*it).file()->save(); diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 3a30fd4a..e1252193 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -233,7 +233,7 @@ PropertyMap APE::Tag::setProperties(const PropertyMap &origProps) toRemove.append(remIt->first); } - for (StringList::Iterator removeIt = toRemove.begin(); removeIt != toRemove.end(); removeIt++) + for(StringList::ConstIterator removeIt = toRemove.begin(); removeIt != toRemove.end(); removeIt++) removeItem(*removeIt); // now sync in the "forward direction" diff --git a/taglib/mod/modtag.cpp b/taglib/mod/modtag.cpp index 14c4c741..4ba72117 100644 --- a/taglib/mod/modtag.cpp +++ b/taglib/mod/modtag.cpp @@ -158,7 +158,7 @@ PropertyMap Mod::Tag::setProperties(const PropertyMap &origProps) // for each tag that has been set above, remove the first entry in the corresponding // value list. The others will be returned as unsupported by this format. - for(StringList::Iterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) { + for(StringList::ConstIterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) { if(properties[*it].size() == 1) properties.erase(*it); else diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index 75a16cd4..09630a70 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -612,11 +612,11 @@ MP4::Tag::saveExisting(ByteVector &data, AtomList &path) long length = ilst->length; MP4::Atom *meta = path[path.size() - 2]; - AtomList::Iterator index = meta->children.find(ilst); + AtomList::ConstIterator index = meta->children.find(ilst); // check if there is an atom before 'ilst', and possibly use it as padding if(index != meta->children.begin()) { - AtomList::Iterator prevIndex = index; + AtomList::ConstIterator prevIndex = index; prevIndex--; MP4::Atom *prev = *prevIndex; if(prev->name == "free") { @@ -625,7 +625,7 @@ MP4::Tag::saveExisting(ByteVector &data, AtomList &path) } } // check if there is an atom after 'ilst', and possibly use it as padding - AtomList::Iterator nextIndex = index; + AtomList::ConstIterator nextIndex = index; nextIndex++; if(nextIndex != meta->children.end()) { MP4::Atom *next = *nextIndex; diff --git a/taglib/mpeg/id3v2/frames/chapterframe.cpp b/taglib/mpeg/id3v2/frames/chapterframe.cpp index b1741cd2..3180e1e0 100644 --- a/taglib/mpeg/id3v2/frames/chapterframe.cpp +++ b/taglib/mpeg/id3v2/frames/chapterframe.cpp @@ -68,7 +68,7 @@ ChapterFrame::ChapterFrame(const ByteVector &eID, const uint &sT, const uint &eT d->startOffset = sO; d->endOffset = eO; FrameList l = eF; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) addEmbeddedFrame(*it); d->factory = FrameFactory::instance(); } @@ -169,7 +169,7 @@ void ChapterFrame::removeEmbeddedFrame(Frame *frame, bool del) void ChapterFrame::removeEmbeddedFrames(const ByteVector &id) { FrameList l = d->embeddedFrameListMap[id]; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) removeEmbeddedFrame(*it, true); } @@ -251,7 +251,7 @@ ByteVector ChapterFrame::renderFields() const data.append(ByteVector::fromUInt(d->startOffset, true)); data.append(ByteVector::fromUInt(d->endOffset, true)); FrameList l = d->embeddedFrameList; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) data.append((*it)->render()); return data; diff --git a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp index 26f5a541..9ba00227 100644 --- a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp +++ b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp @@ -63,7 +63,7 @@ TableOfContentsFrame::TableOfContentsFrame(const ByteVector &eID, const ByteVect d->elementID = eID; d->childElements = ch; FrameList l = eF; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) addEmbeddedFrame(*it); d->factory = FrameFactory::instance(); } @@ -170,7 +170,7 @@ void TableOfContentsFrame::removeEmbeddedFrame(Frame *frame, bool del) void TableOfContentsFrame::removeEmbeddedFrames(const ByteVector &id) { FrameList l = d->embeddedFrameListMap[id]; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) removeEmbeddedFrame(*it, true); } @@ -278,7 +278,7 @@ ByteVector TableOfContentsFrame::renderFields() const it++; } FrameList l = d->embeddedFrameList; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) data.append((*it)->render()); return data; diff --git a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp index 70ea50f8..b77dd547 100644 --- a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp +++ b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp @@ -211,12 +211,12 @@ void TextIdentificationFrame::parseFields(const ByteVector &data) // append those split values to the list and make sure that the new string's // type is the same specified for this frame - for(ByteVectorList::Iterator it = l.begin(); it != l.end(); it++) { + for(ByteVectorList::ConstIterator it = l.begin(); it != l.end(); it++) { if(!(*it).isEmpty()) { if(d->textEncoding == String::Latin1) d->fieldList.append(Tag::latin1StringHandler()->parse(*it)); else - d->fieldList.append(String(*it, d->textEncoding)); + d->fieldList.append(String(*it, d->textEncoding)); } } } @@ -394,7 +394,7 @@ UserTextIdentificationFrame *UserTextIdentificationFrame::find( ID3v2::Tag *tag, const String &description) // static { FrameList l = tag->frameList("TXXX"); - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) { + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) { UserTextIdentificationFrame *f = dynamic_cast(*it); if(f && f->description() == description) return f; diff --git a/taglib/mpeg/id3v2/frames/urllinkframe.cpp b/taglib/mpeg/id3v2/frames/urllinkframe.cpp index 6bcbbda4..1225b524 100644 --- a/taglib/mpeg/id3v2/frames/urllinkframe.cpp +++ b/taglib/mpeg/id3v2/frames/urllinkframe.cpp @@ -169,7 +169,7 @@ PropertyMap UserUrlLinkFrame::asProperties() const UserUrlLinkFrame *UserUrlLinkFrame::find(ID3v2::Tag *tag, const String &description) // static { FrameList l = tag->frameList("WXXX"); - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) { + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) { UserUrlLinkFrame *f = dynamic_cast(*it); if(f && f->description() == description) return f; diff --git a/taglib/mpeg/id3v2/id3v2framefactory.cpp b/taglib/mpeg/id3v2/id3v2framefactory.cpp index 9055be56..e2b1d0de 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.cpp +++ b/taglib/mpeg/id3v2/id3v2framefactory.cpp @@ -268,22 +268,22 @@ Frame *FrameFactory::createFrame(const ByteVector &origData, Header *tagHeader) if(frameID == "PRIV") return new PrivateFrame(data, header); - + // Ownership (frames 4.22) - + if(frameID == "OWNE") { OwnershipFrame *f = new OwnershipFrame(data, header); d->setTextEncoding(f); return f; } - + // Chapter (ID3v2 chapters 1.0) - + if(frameID == "CHAP") return new ChapterFrame(data, header); - + // Table of contents (ID3v2 chapters 1.0) - + if(frameID == "CTOC") return new TableOfContentsFrame(data, header); @@ -458,7 +458,7 @@ void FrameFactory::updateGenre(TextIdentificationFrame *frame) const StringList fields = frame->fieldList(); StringList newfields; - for(StringList::Iterator it = fields.begin(); it != fields.end(); ++it) { + for(StringList::ConstIterator it = fields.begin(); it != fields.end(); ++it) { String s = *it; int end = s.find(")"); diff --git a/taglib/mpeg/id3v2/id3v2header.cpp b/taglib/mpeg/id3v2/id3v2header.cpp index ad6b3aa7..10381053 100644 --- a/taglib/mpeg/id3v2/id3v2header.cpp +++ b/taglib/mpeg/id3v2/id3v2header.cpp @@ -215,7 +215,7 @@ void Header::parse(const ByteVector &data) return; } - for(ByteVector::Iterator it = sizeData.begin(); it != sizeData.end(); it++) { + for(ByteVector::ConstIterator it = sizeData.begin(); it != sizeData.end(); it++) { if(uchar(*it) >= 128) { d->tagSize = 0; debug("TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128."); diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index 57637a36..715cb1bc 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -356,7 +356,7 @@ void ID3v2::Tag::removeFrame(Frame *frame, bool del) void ID3v2::Tag::removeFrames(const ByteVector &id) { FrameList l = d->frameListMap[id]; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) removeFrame(*it, true); } @@ -469,7 +469,7 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const ID3v2::TextIdentificationFrame *frameTDRC = 0; ID3v2::TextIdentificationFrame *frameTIPL = 0; ID3v2::TextIdentificationFrame *frameTMCL = 0; - for(FrameList::Iterator it = d->frameList.begin(); it != d->frameList.end(); it++) { + for(FrameList::ConstIterator it = d->frameList.begin(); it != d->frameList.end(); it++) { ID3v2::Frame *frame = *it; ByteVector frameID = frame->header()->frameID(); for(int i = 0; unsupportedFrames[i]; i++) { @@ -583,7 +583,7 @@ ByteVector ID3v2::Tag::render(int version) const downgradeFrames(&frameList, &newFrames); } - for(FrameList::Iterator it = frameList.begin(); it != frameList.end(); it++) { + for(FrameList::ConstIterator it = frameList.begin(); it != frameList.end(); it++) { (*it)->header()->setVersion(version); if((*it)->header()->frameID().size() != 4) { debug("A frame of unsupported or unknown type \'" diff --git a/taglib/ogg/oggfile.cpp b/taglib/ogg/oggfile.cpp index cc30f9ce..dfd81ec6 100644 --- a/taglib/ogg/oggfile.cpp +++ b/taglib/ogg/oggfile.cpp @@ -354,7 +354,7 @@ void Ogg::File::writePageGroup(const List &thePageGroup) // create a gap for the new pages int numberOfNewPages = pages.back()->header()->pageSequenceNumber() - pageGroup.back(); - List::Iterator pageIter = d->pages.begin(); + List::ConstIterator pageIter = d->pages.begin(); for(int i = 0; i < pageGroup.back(); i++) { if(pageIter != d->pages.end()) { ++pageIter; diff --git a/taglib/tag.cpp b/taglib/tag.cpp index 67634081..98c23043 100644 --- a/taglib/tag.cpp +++ b/taglib/tag.cpp @@ -141,7 +141,7 @@ PropertyMap Tag::setProperties(const PropertyMap &origProps) // for each tag that has been set above, remove the first entry in the corresponding // value list. The others will be returned as unsupported by this format. - for(StringList::Iterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) { + for(StringList::ConstIterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) { if(properties[*it].size() == 1) properties.erase(*it); else diff --git a/taglib/toolkit/tpropertymap.cpp b/taglib/toolkit/tpropertymap.cpp index 3317cc92..313d7fb4 100644 --- a/taglib/toolkit/tpropertymap.cpp +++ b/taglib/toolkit/tpropertymap.cpp @@ -154,12 +154,12 @@ String PropertyMap::toString() const void PropertyMap::removeEmpty() { - StringList emptyKeys; - for(Iterator it = begin(); it != end(); ++it) - if(it->second.isEmpty()) - emptyKeys.append(it->first); - for(StringList::Iterator emptyIt = emptyKeys.begin(); emptyIt != emptyKeys.end(); emptyIt++ ) - erase(*emptyIt); + PropertyMap m; + for(ConstIterator it = begin(); it != end(); ++it) { + if(!it->second.isEmpty()) + m.insert(it->first, it->second); + } + *this = m; } StringList &PropertyMap::unsupportedData() diff --git a/taglib/xm/xmfile.cpp b/taglib/xm/xmfile.cpp index 50161fe4..7fe6f108 100644 --- a/taglib/xm/xmfile.cpp +++ b/taglib/xm/xmfile.cpp @@ -329,7 +329,7 @@ public: uint read(TagLib::File &file, uint limit) { uint sumcount = 0; - for(List::Iterator i = m_readers.begin(); + for(List::ConstIterator i = m_readers.begin(); limit > 0 && i != m_readers.end(); ++ i) { uint count = (*i)->read(file, limit); limit -= count;