From b188fefecaf03c1f30ee4752c2235975058553e2 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 21 Jun 2017 15:27:34 -0700 Subject: [triplet] Use pointer to instance-controlled strings and cache hashcode --- toolsrc/include/triplet.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/triplet.h b/toolsrc/include/triplet.h index e634afd3f..be3bcf5b3 100644 --- a/toolsrc/include/triplet.h +++ b/toolsrc/include/triplet.h @@ -4,8 +4,13 @@ namespace vcpkg { + struct TripletInstance; + struct Triplet { + public: + constexpr Triplet() : m_instance(&default_instance) {} + static Triplet from_canonical_name(const std::string& triplet_as_string); static const Triplet X86_WINDOWS; @@ -16,28 +21,23 @@ namespace vcpkg const std::string& canonical_name() const; const std::string& to_string() const; + size_t hash_code() const; + + bool operator==(const Triplet& other) const; private: - std::string m_canonical_name; - }; + static const TripletInstance default_instance; - bool operator==(const Triplet& left, const Triplet& right); + constexpr Triplet(const TripletInstance* ptr) : m_instance(ptr) {} + + const TripletInstance* m_instance; + }; bool operator!=(const Triplet& left, const Triplet& right); } -namespace std +template<> +struct std::hash { - template<> - struct hash - { - size_t operator()(const vcpkg::Triplet& t) const - { - std::hash hasher; - size_t hash = 17; - hash = hash * 31 + hasher(t.canonical_name()); - return hash; - } - }; - -} // namespace std + size_t operator()(const vcpkg::Triplet& t) const { return t.hash_code(); } +}; -- cgit v1.2.3