Skip to content

Commit

Permalink
libcore: File index and config profiles are indexed case-insensitively
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent c08986d commit b634c78
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
1 change: 1 addition & 0 deletions doomsday/libs/core/include/de/data/cstring.h
Expand Up @@ -78,6 +78,7 @@ class DE_PUBLIC CString
Char first() const { return *mb_iterator(begin()); }
String lower() const;
String upper() const;
std::string toStdString() const { return {begin(), end()}; }

static size_t npos;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/data/profiles.h
Expand Up @@ -142,7 +142,7 @@ class DE_PUBLIC Profiles
*/
StringList profiles() const;

LoopResult forAll(std::function<LoopResult (AbstractProfile &)> func) const;
LoopResult forAll(const std::function<LoopResult (AbstractProfile &)>& func) const;

/**
* Returns the total number of profiles.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/filesys/fileindex.h
Expand Up @@ -39,7 +39,7 @@ class Package;
class DE_PUBLIC FileIndex
{
public:
typedef std::multimap<String, File *> Index;
typedef std::multimap<String, File *, String::InsensitiveLessThan> Index;
typedef std::pair<Index::iterator, Index::iterator> IndexRange;
typedef std::list<File *> FoundFiles;

Expand Down
33 changes: 13 additions & 20 deletions doomsday/libs/core/src/data/profiles.cpp
Expand Up @@ -24,15 +24,10 @@

namespace de {

static String nameToKey(const String &name)
{
return name.lower();
}

DE_PIMPL(Profiles)
, DE_OBSERVES(Deletable, Deletion)
{
typedef Map<String, AbstractProfile *> Profiles;
typedef Map<String, AbstractProfile *, String::InsensitiveLessThan> Profiles;
Profiles profiles;
String persistentName;

Expand All @@ -46,8 +41,8 @@ DE_PIMPL(Profiles)

void add(AbstractProfile *profile)
{
String const key = nameToKey(profile->name());
if (profiles.contains(nameToKey(key)))
String const key = profile->name();
if (profiles.contains(key))
{
delete profiles[key];
}
Expand All @@ -65,7 +60,7 @@ DE_PIMPL(Profiles)
{
profile.audienceForDeletion -= this;
profile.setOwner(nullptr);
profiles.remove(nameToKey(profile.name()));
profiles.remove(profile.name());

DE_FOR_PUBLIC_AUDIENCE2(Removal, i)
{
Expand All @@ -75,20 +70,18 @@ DE_PIMPL(Profiles)

void changeLookupKey(AbstractProfile const &profile, String const &newName)
{
profiles.remove(nameToKey(profile.name()));
profiles.insert(nameToKey(newName), const_cast<AbstractProfile *>(&profile));
profiles.remove(profile.name());
profiles.insert(newName, const_cast<AbstractProfile *>(&profile));
}

void objectWasDeleted(Deletable *obj)
{
// At this point the AbstractProfile itself is already deleted.
MutableMapIterator<String, AbstractProfile *> iter(profiles);
while (iter.hasNext())
for (auto i = profiles.begin(); i != profiles.end(); ++i)
{
iter.next();
if (iter.value() == obj)
if (i->second == obj)
{
iter.remove();
profiles.erase(i);
break;
}
}
Expand Down Expand Up @@ -182,7 +175,7 @@ int Profiles::count() const

Profiles::AbstractProfile *Profiles::tryFind(String const &name) const
{
auto found = d->profiles.find(nameToKey(name));
auto found = d->profiles.find(name);
if (found != d->profiles.end())
{
return found->second;
Expand Down Expand Up @@ -214,7 +207,7 @@ bool Profiles::isPersistent() const
return !d->persistentName.isEmpty();
}

LoopResult Profiles::forAll(std::function<LoopResult (AbstractProfile &)> func) const
LoopResult Profiles::forAll(const std::function<LoopResult (AbstractProfile &)>& func) const
{
for (const auto &prof : d->profiles)
{
Expand Down Expand Up @@ -271,9 +264,9 @@ void Profiles::serialize() const

os << "\nprofile {\n"
" name: " << prof->name().c_str() << "\n";
for (auto line : prof->toInfoSource().split('\n'))
for (const auto &line : prof->toInfoSource().splitRef('\n'))
{
os << " " << line.c_str() << "\n";
os << " " << line.toStdString() << "\n";
}
os << "}\n";
++count;
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libs/core/src/filesys/fileindex.cpp
Expand Up @@ -40,10 +40,10 @@ DE_PIMPL(FileIndex), public Lockable

static String indexedName(File const &file)
{
String name = file.name().lower();
String name = file.name();

// Ignore the package version in the indexed names.
if (name.endsWith(".pack"))
if (name.endsWith(".pack", CaseInsensitive))
{
name = Package::split(name.fileNameWithoutExtension()).first + ".pack";
}
Expand Down Expand Up @@ -83,8 +83,8 @@ DE_PIMPL(FileIndex), public Lockable

void findPartialPath(const String &path, FoundFiles &found) const
{
String baseName = path.fileName().lower();
String dir = path.fileNamePath().lower();
String baseName = path.fileName();
String dir = path.fileNamePath();

if (!dir.empty() && !dir.beginsWith("/"))
{
Expand Down

0 comments on commit b634c78

Please sign in to comment.