diff options
author | Chad Austin <chad@imvu.com> | 2013-04-16 18:46:47 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-18 20:08:19 +0300 |
commit | a76d9ceaee0a83c0af562753ad5efd01858c1c8b (patch) | |
tree | c14656d727b59bbd89c849467f65c5973075ccfe | |
parent | e5c04828c4c2eaec83cf25b83067064db2270c2e (diff) |
switch to EMSCRIPTEN_SYMBOL which improves code size a bit by storing the pointer to the string literal as a constant as opposed to a global variable.
-rw-r--r-- | system/include/emscripten/val.h | 22 | ||||
-rw-r--r-- | tests/embind/embind_test.cpp | 4 |
2 files changed, 9 insertions, 17 deletions
diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index 42d8d375..09cad80e 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -56,25 +56,17 @@ namespace emscripten { } } - class symbol { - public: - symbol() = delete; - - // I so wish I could require the argument to be a string literal - symbol(const char* address) - : address(address) - { + template<const char* address> + struct symbol_registrar { + symbol_registrar() { internal::_emval_register_symbol(address); } - - operator const char*() const { - return address; - } - - private: - const char* address; }; +#define EMSCRIPTEN_SYMBOL(name) \ + static const char name##_symbol[] = #name; \ + static const symbol_registrar<name##_symbol> name##_registrar + class val { public: // missing operators: diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 9bab2872..04771dbe 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -1087,7 +1087,7 @@ public: }
};
-symbol optionalMethodSymbol = "optionalMethod";
+EMSCRIPTEN_SYMBOL(optionalMethod);
class AbstractClassWrapper : public wrapper<AbstractClass> {
public:
@@ -1097,7 +1097,7 @@ public: return call<std::string>("abstractMethod");
}
std::string optionalMethod(std::string s) const {
- return optional_call<std::string>(optionalMethodSymbol, [&] {
+ return optional_call<std::string>(optionalMethod_symbol, [&] {
return AbstractClass::optionalMethod(s);
}, s);
}
|