Avoid unnecessary detaching of containers

If only a constant iterator is needed, make the container const if
possible, otherwise use cbegin() and cend() to get a constant iterator
without detaching the container.

These fixes are needed so that `auto` can deduce the correct
iterator type.
This commit is contained in:
Urs Fleisch
2023-07-15 20:53:49 +02:00
parent b273505c28
commit 63922f2676
42 changed files with 218 additions and 116 deletions

View File

@@ -74,8 +74,8 @@ namespace
if(::strlen(fileName) == 0)
return nullptr;
#endif
ResolverList::ConstIterator it = fileTypeResolvers.begin();
for(; it != fileTypeResolvers.end(); ++it) {
ResolverList::ConstIterator it = fileTypeResolvers.cbegin();
for(; it != fileTypeResolvers.cend(); ++it) {
File *file = (*it)->createFile(fileName, readAudioProperties, audioPropertiesStyle);
if(file)
return file;
@@ -87,8 +87,8 @@ namespace
File *detectByResolvers(IOStream* stream, bool readAudioProperties,
AudioProperties::ReadStyle audioPropertiesStyle)
{
for(ResolverList::ConstIterator it = fileTypeResolvers.begin();
it != fileTypeResolvers.end(); ++it) {
for(ResolverList::ConstIterator it = fileTypeResolvers.cbegin();
it != fileTypeResolvers.cend(); ++it) {
if(const FileRef::StreamTypeResolver *streamResolver =
dynamic_cast<const FileRef::StreamTypeResolver*>(*it)) {
if(File *file = streamResolver->createFileFromStream(