KEntryMap: for read access use heterogeneous lookup with view-like key type
Currently any look-up in KEntryMap requires a full instance of the key type. Which in turn require a QString & QByteArray instance for group name & key name respectively, as the members of KEntryKey type. As the key name type supported in the public API currently can be either QString or const char* (to UTF-8), this needs a deep copy into the QByteArray instance used with KEntryKey instance used for the look-up.
std::map, as base class of KEntryMap, since C++14 supports heterogeneous lookup, by the third template argument Compare. It enables to inject further overloads of find(Key) with custom types.
So this introdudes a light-weight variant KEntryKeyView which uses views instead of QString & QByteArray. The class is deployed for any read-only look-up in the map. KEntryMapTest is extended to test the comparisons between the normal key type and the view type. KEntryMap's & KConfigPrivate's read-access API are adapted to take in the key type as view. This avoids the deep copy currently happening for all the const char* arguments to a QByteArray instance in the KConfigPrivate methods.
A new benchmark KConfigBenchmark is added. It for now tests the execution time of KConfigGroup::hasKey() and KConfigGroup::readEntry(). It has been used to show a execution time reduction of ~ 15% by the above given code changes.
Average of 3 for bin/kconfig_benchmark -iterations 10000000
:
testHasKey: | Before | After | Reduction by |
---|---|---|---|
0,00053363 s | 0,000446733 s | 16,28 % |
testReadEntry: | Before | After | Reduction by |
---|---|---|---|
0,00060057 s | 0,00051773 s | 13,79 % |