aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-04-16 14:25:01 -0700
committerJukka Jylänki <jujjyl@gmail.com>2013-04-18 20:08:18 +0300
commit775f840e378eba5a9a8053857113a40efb980fb7 (patch)
tree943b087d78c6e8d32ce5cfa48d82bf1626f5c49d /system
parentd990cb17d8c43913a733c28601f4319fce90c27a (diff)
Add perfect forwarding throughout emscripten::val. This shaves 50 KB off the non-minified JS in Northstar.
Diffstat (limited to 'system')
-rwxr-xr-xsystem/include/emscripten/bind.h10
-rw-r--r--system/include/emscripten/val.h21
2 files changed, 22 insertions, 9 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index 894586a6..a3886031 100755
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -284,8 +284,8 @@ namespace emscripten {
}
template<typename WrapperType, typename ClassType, typename... Args>
- WrapperType wrapped_new(Args... args) {
- return WrapperType(new ClassType(args...));
+ WrapperType wrapped_new(Args&&... args) {
+ return WrapperType(new ClassType(std::forward<Args>(args)...));
}
template<typename ClassType, typename... Args>
@@ -718,8 +718,8 @@ namespace emscripten {
template<typename T>
class wrapper : public T {
public:
- explicit wrapper(const val& wrapped)
- : wrapped(wrapped)
+ explicit wrapper(val&& wrapped)
+ : wrapped(std::forward<val>(wrapped))
{}
template<typename ReturnType, typename... Args>
@@ -760,7 +760,7 @@ namespace emscripten {
};
#define EMSCRIPTEN_WRAPPER(T) \
- T(const ::emscripten::val& v): wrapper(v) {}
+ T(::emscripten::val&& v): wrapper(std::forward<::emscripten::val>(v)) {}
namespace internal {
struct NoBaseClass {
diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h
index d32c9650..1fccd434 100644
--- a/system/include/emscripten/val.h
+++ b/system/include/emscripten/val.h
@@ -101,18 +101,24 @@ namespace emscripten {
}
template<typename T>
- explicit val(const T& value) {
+ explicit val(T&& value) {
typedef internal::BindingType<T> BT;
auto taker = reinterpret_cast<internal::EM_VAL (*)(internal::TYPEID, typename BT::WireType)>(&internal::_emval_take_value);
- handle = taker(internal::TypeID<T>::get(), BT::toWireType(value));
+ handle = taker(internal::TypeID<T>::get(), BT::toWireType(std::forward<T>(value)));
}
val() = delete;
- val(const char* v)
+ explicit val(const char* v)
: handle(internal::_emval_new_cstring(v))
{}
+ val(val&& v)
+ : handle(v.handle)
+ {
+ v.handle = 0;
+ }
+
val(const val& v)
: handle(v.handle)
{
@@ -123,6 +129,13 @@ namespace emscripten {
internal::_emval_decref(handle);
}
+ val& operator=(val&& v) {
+ internal::_emval_decref(handle);
+ handle = v.handle;
+ v.handle = 0;
+ return *this;
+ }
+
val& operator=(const val& v) {
internal::_emval_incref(v.handle);
internal::_emval_decref(handle);
@@ -260,7 +273,7 @@ namespace emscripten {
template<>
struct BindingType<val> {
typedef internal::EM_VAL WireType;
- static WireType toWireType(val v) {
+ static WireType toWireType(const val& v) {
_emval_incref(v.handle);
return v.handle;
}