mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 11:18:40 +08:00
cmPropertyMap: Use std::unordered_map as container instead of std::map
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
#include "cmPropertyMap.h"
|
#include "cmPropertyMap.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
void cmPropertyMap::Clear()
|
void cmPropertyMap::Clear()
|
||||||
@@ -59,15 +60,21 @@ std::vector<std::string> cmPropertyMap::GetKeys() const
|
|||||||
for (auto const& item : Map_) {
|
for (auto const& item : Map_) {
|
||||||
keyList.push_back(item.first);
|
keyList.push_back(item.first);
|
||||||
}
|
}
|
||||||
|
std::sort(keyList.begin(), keyList.end());
|
||||||
return keyList;
|
return keyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const
|
std::vector<std::pair<std::string, std::string>> cmPropertyMap::GetList() const
|
||||||
{
|
{
|
||||||
std::vector<std::pair<std::string, std::string>> kvList;
|
typedef std::pair<std::string, std::string> StringPair;
|
||||||
|
std::vector<StringPair> kvList;
|
||||||
kvList.reserve(Map_.size());
|
kvList.reserve(Map_.size());
|
||||||
for (auto const& item : Map_) {
|
for (auto const& item : Map_) {
|
||||||
kvList.emplace_back(item.first, item.second);
|
kvList.emplace_back(item.first, item.second);
|
||||||
}
|
}
|
||||||
|
std::sort(kvList.begin(), kvList.end(),
|
||||||
|
[](StringPair const& a, StringPair const& b) {
|
||||||
|
return a.first < b.first;
|
||||||
|
});
|
||||||
return kvList;
|
return kvList;
|
||||||
}
|
}
|
||||||
|
@@ -5,11 +5,14 @@
|
|||||||
|
|
||||||
#include "cmConfigure.h" // IWYU pragma: keep
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
/** \class cmPropertyMap
|
||||||
|
* \brief String property map.
|
||||||
|
*/
|
||||||
class cmPropertyMap
|
class cmPropertyMap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -34,6 +37,7 @@ public:
|
|||||||
void RemoveProperty(const std::string& name);
|
void RemoveProperty(const std::string& name);
|
||||||
|
|
||||||
// -- Lists
|
// -- Lists
|
||||||
|
|
||||||
//! Get a sorted list of property keys
|
//! Get a sorted list of property keys
|
||||||
std::vector<std::string> GetKeys() const;
|
std::vector<std::string> GetKeys() const;
|
||||||
|
|
||||||
@@ -41,7 +45,7 @@ public:
|
|||||||
std::vector<std::pair<std::string, std::string>> GetList() const;
|
std::vector<std::pair<std::string, std::string>> GetList() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::string> Map_;
|
std::unordered_map<std::string, std::string> Map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user