Merge pull request #430 from TsudaKageyu/const-iterator

Reduce useless detach operations by making some non-const iterators cons...
This commit is contained in:
Lukáš Lalinský 2014-08-21 09:47:36 +02:00
commit b1a8205561
16 changed files with 38 additions and 38 deletions

View File

@ -233,7 +233,7 @@ void taglib_tag_free_strings()
if(!stringManagementEnabled)
return;
for(List<char *>::Iterator it = strings.begin(); it != strings.end(); ++it)
for(List<char *>::ConstIterator it = strings.begin(); it != strings.end(); ++it)
free(*it);
strings.clear();
}

View File

@ -94,7 +94,7 @@ int main(int argc, char *argv[])
char field = argv[i][1];
TagLib::String value = argv[i + 1];
TagLib::List<TagLib::FileRef>::Iterator it;
TagLib::List<TagLib::FileRef>::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<TagLib::FileRef>::Iterator it;
TagLib::List<TagLib::FileRef>::ConstIterator it;
for(it = fileList.begin(); it != fileList.end(); ++it)
(*it).file()->save();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<UserTextIdentificationFrame *>(*it);
if(f && f->description() == description)
return f;

View File

@ -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<UserUrlLinkFrame *>(*it);
if(f && f->description() == description)
return f;

View File

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

View File

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

View File

@ -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 \'"

View File

@ -354,7 +354,7 @@ void Ogg::File::writePageGroup(const List<int> &thePageGroup)
// create a gap for the new pages
int numberOfNewPages = pages.back()->header()->pageSequenceNumber() - pageGroup.back();
List<Page *>::Iterator pageIter = d->pages.begin();
List<Page *>::ConstIterator pageIter = d->pages.begin();
for(int i = 0; i < pageGroup.back(); i++) {
if(pageIter != d->pages.end()) {
++pageIter;

View File

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

View File

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

View File

@ -329,7 +329,7 @@ public:
uint read(TagLib::File &file, uint limit)
{
uint sumcount = 0;
for(List<Reader*>::Iterator i = m_readers.begin();
for(List<Reader*>::ConstIterator i = m_readers.begin();
limit > 0 && i != m_readers.end(); ++ i) {
uint count = (*i)->read(file, limit);
limit -= count;