From 36573e798c986e298c62daabed6036b12ea0314d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 2 Feb 2010 20:37:50 +0000 Subject: Use Glib string interning (quarks) to make Path/URI operator== very fast. This avoids a ton of string comparison overhead in Ingen when setting various properties (e.g. "ingen:value" was compared several times every time a port value was changed, now this is just a single pointer comparison and the full round trip of a value change does no string comparison at all, but is still property based and RDFey). git-svn-id: http://svn.drobilla.net/lad/trunk/raul@2408 a436a847-0d15-0410-975c-d299462d15a1 --- raul/Symbol.hpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'raul/Symbol.hpp') diff --git a/raul/Symbol.hpp b/raul/Symbol.hpp index 8aa82c1..1a57886 100644 --- a/raul/Symbol.hpp +++ b/raul/Symbol.hpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace Raul { @@ -38,16 +39,15 @@ namespace Raul { * * \ingroup raul */ -class Symbol : public std::basic_string { +class Symbol { public: - /** Construct a Symbol from an std::string. * * It is a fatal error to construct a Symbol from an invalid string, * use is_valid first to check. */ Symbol(const std::basic_string& symbol) - : std::basic_string(symbol) + : _str(g_intern_string(symbol.c_str())) { assert(is_valid(symbol)); } @@ -59,17 +59,35 @@ public: * use is_valid first to check. */ Symbol(const char* csymbol) - : std::basic_string(csymbol) + : _str(g_intern_string(csymbol)) { assert(is_valid(csymbol)); } - static bool is_valid(const std::basic_string& path); + inline const char* c_str() const { return _str; } + + inline bool operator==(const Symbol& other) const { + return _str == other._str; + } + + inline bool operator!=(const Symbol& other) const { + return _str != other._str; + } + + static bool is_valid(const std::basic_string& symbol); static std::string symbolify(const std::basic_string& str); + +private: + const char* _str; }; } // namespace Raul +static inline std::ostream& operator<<(std::ostream& os, const Raul::Symbol& symbol) +{ + return (os << symbol.c_str()); +} + #endif // RAUL_SYMBOL_HPP -- cgit v1.2.1