public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] libstdc++/66059 optimise std::make_integer_sequence
@ 2015-11-17 19:54 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2015-11-17 19:54 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 540 bytes --]

I've been talking about a compiler built-in to implement
make_integer_sequence since before the proposal even made it into the
standard, so I tried to implement one that would allow:

template<typename _Tp, _Tp _Num>
  using make_integer_sequence = integer_sequence< __intseq(_Tp, _Num) >;

But I don't know the front-end well enough to make that work.

Instead here's a much more efficient implementation that takes a
divide-and-conquer approach rather than building the sequence
linearly.

Tested powerpc64le-linux, committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1569 bytes --]

commit 4bd998a906972eb9ae47ffd87f28b17816112318
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Nov 17 17:55:25 2015 +0000

    PR libstdc++/66059 optimise _Build_index_tuple
    
    	PR libstdc++/66059
    	* include/std/utility (_Build_index_tuple): Optimise.

diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility
index 89b6852..985bcb2 100644
--- a/libstdc++-v3/include/std/utility
+++ b/libstdc++-v3/include/std/utility
@@ -212,17 +212,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // Stores a tuple of indices.  Used by tuple and pair, and by bind() to
   // extract the elements in a tuple.
-  template<size_t... _Indexes>
-    struct _Index_tuple
+  template<size_t... _Indexes> struct _Index_tuple { };
+
+  // Concatenates two _Index_tuples.
+  template<typename _Itup1, typename _Itup2> struct _Itup_cat;
+
+  template<size_t... _Ind1, size_t... _Ind2>
+    struct _Itup_cat<_Index_tuple<_Ind1...>, _Index_tuple<_Ind2...>>
     {
-      typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
+      using __type = _Index_tuple<_Ind1..., (_Ind2 + sizeof...(_Ind1))...>;
     };
 
   // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
   template<size_t _Num>
     struct _Build_index_tuple
+    : _Itup_cat<typename _Build_index_tuple<_Num / 2>::__type,
+		typename _Build_index_tuple<_Num - _Num / 2>::__type>
+    { };
+
+  template<>
+    struct _Build_index_tuple<1>
     {
-      typedef typename _Build_index_tuple<_Num - 1>::__type::__next __type;
+      typedef _Index_tuple<0> __type;
     };
 
   template<>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-11-17 19:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17 19:54 [patch] libstdc++/66059 optimise std::make_integer_sequence Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).