clover: Optimize module serialization for vectors of fundamental types.
authorFrancisco Jerez <currojerez@riseup.net>
Sat, 14 Jun 2014 18:53:35 +0000 (20:53 +0200)
committerFrancisco Jerez <currojerez@riseup.net>
Thu, 19 Jun 2014 18:17:08 +0000 (20:17 +0200)
Tested-by: Tom Stellard <thomas.stellard@amd.com>
src/gallium/state_trackers/clover/core/module.cpp

index 3e3ad99..41de734 100644 (file)
@@ -69,7 +69,9 @@ namespace {
 
    /// (De)serialize a vector.
    template<typename T>
-   struct _serializer<compat::vector<T>> {
+   struct _serializer<compat::vector<T>,
+                      typename std::enable_if<
+                         !std::is_scalar<T>::value>::type> {
       static void
       proc(compat::ostream &os, const compat::vector<T> &v) {
          _proc<uint32_t>(os, v.size());
@@ -87,6 +89,25 @@ namespace {
       }
    };
 
+   template<typename T>
+   struct _serializer<compat::vector<T>,
+                      typename std::enable_if<
+                         std::is_scalar<T>::value>::type> {
+      static void
+      proc(compat::ostream &os, const compat::vector<T> &v) {
+         _proc<uint32_t>(os, v.size());
+         os.write(reinterpret_cast<const char *>(v.begin()),
+                  v.size() * sizeof(T));
+      }
+
+      static void
+      proc(compat::istream &is, compat::vector<T> &v) {
+         v.reserve(_proc<uint32_t>(is));
+         is.read(reinterpret_cast<char *>(v.begin()),
+                 v.size() * sizeof(T));
+      }
+   };
+
    /// (De)serialize a module::section.
    template<>
    struct _serializer<module::section> {