summaryrefslogtreecommitdiffstats
path: root/raul/Symbol.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-02-02 20:37:50 +0000
committerDavid Robillard <d@drobilla.net>2010-02-02 20:37:50 +0000
commit36573e798c986e298c62daabed6036b12ea0314d (patch)
treec908c681c6f584831366283bf7c099b36f94ff52 /raul/Symbol.hpp
parent53648252376649bca9868aec48ad4a290e3ae073 (diff)
downloadraul-36573e798c986e298c62daabed6036b12ea0314d.tar.gz
raul-36573e798c986e298c62daabed6036b12ea0314d.tar.bz2
raul-36573e798c986e298c62daabed6036b12ea0314d.zip
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
Diffstat (limited to 'raul/Symbol.hpp')
-rw-r--r--raul/Symbol.hpp28
1 files changed, 23 insertions, 5 deletions
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 <string>
#include <cstring>
#include <cassert>
+#include <glib.h>
namespace Raul {
@@ -38,16 +39,15 @@ namespace Raul {
*
* \ingroup raul
*/
-class Symbol : public std::basic_string<char> {
+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<char>& symbol)
- : std::basic_string<char>(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<char>(csymbol)
+ : _str(g_intern_string(csymbol))
{
assert(is_valid(csymbol));
}
- static bool is_valid(const std::basic_string<char>& 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<char>& symbol);
static std::string symbolify(const std::basic_string<char>& 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