diff --git a/doomsday/libs/core/include/de/data/hash.h b/doomsday/libs/core/include/de/data/hash.h index 58e61caf5e..7991c1e01c 100644 --- a/doomsday/libs/core/include/de/data/hash.h +++ b/doomsday/libs/core/include/de/data/hash.h @@ -27,10 +27,13 @@ namespace de { * Efficient key-value container with unordered keys (based on std::unordered_map). * @ingroup data */ -template -class Hash : public std::unordered_map +template , + typename KeyEqual = std::equal_to> +class Hash : public std::unordered_map { - using Base = std::unordered_map; + using Base = std::unordered_map; public: Hash() {} @@ -65,30 +68,33 @@ class Hash : public std::unordered_map } }; -template +template , + typename KeyEqual = std::equal_to> class MutableHashIterator { - using Container = Hash; + using Container = Hash; using Iterator = typename Container::iterator; Container _hash; + Iterator _iter; Iterator _cur; - Iterator _next; public: MutableHashIterator(Container &c) : _hash(c) { - if (!_hash.empty()) _next = c.begin(); + _iter = _hash.begin(); } bool hasNext() const { - return !_hash.empty() && _next != _hash.end(); + return _iter != _hash.end(); } Iterator &next() { - _cur = _next++; + _cur = _iter++; return _cur; } @@ -104,7 +110,7 @@ class MutableHashIterator void remove() { - _hash.erase(_cur); + _iter = _hash.erase(_cur); } }; } // namespace de diff --git a/doomsday/libs/core/include/de/data/map.h b/doomsday/libs/core/include/de/data/map.h index 00345dfc11..750f59aed6 100644 --- a/doomsday/libs/core/include/de/data/map.h +++ b/doomsday/libs/core/include/de/data/map.h @@ -26,10 +26,10 @@ namespace de { /** * Key-value container with ordered keys (based on std::map). */ -template -class Map : public std::map +template > +class Map : public std::map { - using Base = std::map; + using Base = std::map; public: Map() {} @@ -59,31 +59,30 @@ class Map : public std::map } }; -template +template > class MutableMapIterator { - using Container = Map; + using Container = Map; using Iterator = typename Container::iterator; Container _map; + Iterator _iter; Iterator _cur; - Iterator _next; public: MutableMapIterator(Container &c) : _map(c) { - if (!_map.empty()) _next = c.begin(); + _iter = _map.begin(); } bool hasNext() const { - return !_map.empty() && _next != _map.end(); + return _iter != _map.end(); } Iterator &next() { - _cur = _next; - if (hasNext()) ++_next; + _cur = _iter++; return _cur; } @@ -99,7 +98,7 @@ class MutableMapIterator void remove() { - _map.erase(_cur); + _iter = _map.erase(_cur); } }; diff --git a/doomsday/libs/core/include/de/data/time.h b/doomsday/libs/core/include/de/data/time.h index 6a3461edf0..a0a9f9f2a6 100644 --- a/doomsday/libs/core/include/de/data/time.h +++ b/doomsday/libs/core/include/de/data/time.h @@ -170,7 +170,7 @@ class DE_PUBLIC Time : public ISerializable Time(Time &&moved); Time(const TimePoint &tp); - Time(iTime time); + Time(const iTime &time); Time(int year, int month, int day, int hour, int minute, int second); diff --git a/doomsday/libs/core/include/de/filesys/folder.h b/doomsday/libs/core/include/de/filesys/folder.h index 8b98d7a849..6ae6f58aef 100644 --- a/doomsday/libs/core/include/de/filesys/folder.h +++ b/doomsday/libs/core/include/de/filesys/folder.h @@ -67,7 +67,7 @@ class DE_PUBLIC Folder : public File DE_ERROR(NewFileError); typedef List Feeds; - typedef Map Contents; + typedef Map Contents; enum PopulationBehavior { PopulateFullTree = 0x1, ///< The full tree is populated. diff --git a/doomsday/libs/core/src/data/time.cpp b/doomsday/libs/core/src/data/time.cpp index 7830763e46..40698e4c46 100644 --- a/doomsday/libs/core/src/data/time.cpp +++ b/doomsday/libs/core/src/data/time.cpp @@ -285,7 +285,7 @@ Time::Time(int year, int month, int day, int hour, int minute, int second) Time::Time(const TimePoint &tp) : d(new Impl(tp)) {} -Time::Time(iTime time) : d(new Impl) +Time::Time(const iTime &time) : d(new Impl(0 /* init as invalid */)) { using namespace std::chrono; d->flags |= Impl::SysTime; diff --git a/doomsday/libs/core/src/filesys/directoryfeed.cpp b/doomsday/libs/core/src/filesys/directoryfeed.cpp index 3a4eb35ffe..76abc6b114 100644 --- a/doomsday/libs/core/src/filesys/directoryfeed.cpp +++ b/doomsday/libs/core/src/filesys/directoryfeed.cpp @@ -106,7 +106,6 @@ Feed::PopulatedFiles DirectoryFeed::populate(Folder const &folder) { continue; } - if (name == ".." || name.first() == '.') continue; if (isDirectory_FileInfo(i.value)) { diff --git a/doomsday/libs/core/src/filesys/file.cpp b/doomsday/libs/core/src/filesys/file.cpp index c201164f35..251e9ccb8d 100644 --- a/doomsday/libs/core/src/filesys/file.cpp +++ b/doomsday/libs/core/src/filesys/file.cpp @@ -81,7 +81,7 @@ File::~File() { // If we own a source, get rid of it. delete d->source; - d->source = 0; + d->source = nullptr; } if (Folder *parentFolder = parent()) { diff --git a/doomsday/libs/core/src/filesys/folder.cpp b/doomsday/libs/core/src/filesys/folder.cpp index 849a9c643d..4810ff1883 100644 --- a/doomsday/libs/core/src/filesys/folder.cpp +++ b/doomsday/libs/core/src/filesys/folder.cpp @@ -66,7 +66,7 @@ DE_PIMPL(Folder) void add(File *file) { - contents.insert(file->name().lower(), file); + contents.insert(file->name(), file); file->setParent(thisPublic); } @@ -216,22 +216,21 @@ void Folder::populate(PopulationBehaviors behavior) DE_GUARD(this); // Prune the existing files first. - MutableMapIterator iter(d->contents); - while (iter.hasNext()) + for (auto iter = d->contents.begin(); iter != d->contents.end(); ) { - iter.next(); - // By default we will NOT prune if there are no feeds attached to the folder. // In this case the files were probably created manually, so we shouldn't // touch them. bool mustPrune = false; - File *file = iter.value(); + File *file = iter->second; if (file->mode() & DontPrune) { // Skip this one, it should be kept as-is until manually deleted. + ++iter; continue; } + Feed *originFeed = file->originFeed(); // If the file has a designated feed, ask it about pruning. @@ -245,11 +244,11 @@ void Folder::populate(PopulationBehaviors behavior) // There is no designated feed, ask all feeds of this folder. // If even one of the feeds thinks that the file is out of date, // it will be pruned. - for (Feeds::iterator f = d->feeds.begin(); f != d->feeds.end(); ++f) + for (auto *f : d->feeds) { - if ((*f)->prune(*file)) + if (f->prune(*file)) { - LOG_RES_XVERBOSE("Pruning %s due to non-origin feed %s", file->path() << (*f)->description()); + LOG_RES_XVERBOSE("Pruning %s due to non-origin feed %s", file->path() << f->description()); mustPrune = true; break; } @@ -260,9 +259,13 @@ void Folder::populate(PopulationBehaviors behavior) { // It needs to go. file->setParent(nullptr); - iter.remove(); + iter = d->contents.erase(iter); delete file; } + else + { + ++iter; + } } } @@ -283,7 +286,7 @@ void Folder::populate(PopulationBehaviors behavior) if (i) { std::unique_ptr file(i); - if (!d->contents.contains(i->name().lower())) + if (!d->contents.contains(i->name())) { d->add(file.release()); fileSystem().index(*i); @@ -475,7 +478,7 @@ bool Folder::has(String const &name) const } DE_GUARD(this); - return (d->contents.find(name.lower()) != d->contents.end()); + return (d->contents.find(name) != d->contents.end()); } File &Folder::add(File *file) @@ -498,10 +501,8 @@ File *Folder::remove(const String &name) { DE_GUARD(this); - String const key = name.lower(); - DE_ASSERT(d->contents.contains(key)); - - File *removed = d->contents.take(key); + DE_ASSERT(d->contents.contains(name)); + File *removed = d->contents.take(name); removed->setParent(nullptr); return removed; } @@ -520,7 +521,7 @@ filesys::Node const *Folder::tryGetChild(String const &name) const { DE_GUARD(this); - auto found = d->contents.find(name.lower()); + auto found = d->contents.find(name); if (found != d->contents.end()) { return found->second;