Browse Source

Cutting number of copies in half by using new in the beginning.

Samuel Jaffe 8 years ago
parent
commit
0cef5bf65a
5 changed files with 7 additions and 7 deletions
  1. 1 1
      streams/filter.hpp
  2. 1 1
      streams/join.hpp
  3. 1 1
      streams/map.hpp
  4. 2 2
      streams/source.hpp
  5. 2 2
      streams/streams.hpp

+ 1 - 1
streams/filter.hpp

@@ -55,6 +55,6 @@ namespace stream { namespace detail {
   template <typename T>
   template <typename F>
   auto stream_base<T>::filter(F&& pred) const -> stream_base<T>  {
-    return filter_stream<T>(pred, *this);
+    return new filter_stream<T>(pred, *this);
   }
 } }

+ 1 - 1
streams/join.hpp

@@ -89,7 +89,7 @@ namespace stream { namespace detail {
   template <typename C>
   auto make_join(stream_base<C> const& sb) -> stream_base<typename C::value_type>  {
     using T = typename C::value_type;
-    return join_stream<C>(sb);
+    return new join_stream<C>(sb);
   }
   
   template <typename T>

+ 1 - 1
streams/map.hpp

@@ -37,6 +37,6 @@ namespace stream { namespace detail {
   template <typename T>
   template <typename F>
   auto stream_base<T>::map(F&& func) const -> stream_base<map_f<F>> {
-    return map_stream<T, map_f<F>>(func, *this);
+    return new map_stream<T, map_f<F>>(func, *this);
   }
 } }

+ 2 - 2
streams/source.hpp

@@ -49,7 +49,7 @@ namespace stream {
   
   template <typename C>
   detail::stream_base<detail::source::reference<C>> make_stream(C && cont) {
-    return detail::source_stream<C>(cont);
+    return new detail::source_stream<C>(cont);
   }
   
   template <typename T>
@@ -59,6 +59,6 @@ namespace stream {
 
   template <typename It>
   detail::stream_base<typename It::reference> make_stream(It begin, It end) {
-    return detail::range_stream<It>(begin, end);
+    return new detail::range_stream<It>(begin, end);
   }
 }

+ 2 - 2
streams/streams.hpp

@@ -128,12 +128,12 @@ namespace stream {
       using clean = typename std::decay<T>::type;
     public:
       template <typename Stream>
-      stream_base(Stream && impl) {
+      stream_base(Stream * && impl) {
         copy = [](void * p) { return (void*) new Stream(*(Stream*)(p)); };
         do_begin = [](void * p) -> iterator<T> { return ((Stream*) p)->begin(); };
         do_end = [](void * p) -> iterator<T> { return ((Stream*) p)->end(); };
         destroy = [](void * p) { delete ((Stream*) p); };
-        impl_ = copy(&impl);
+        impl_ = impl;
       }
       
       stream_base(stream_base const & other)