Skip to content

Commit f030618

Browse files
committed
Initial speedup for EDG for the stub functions. The init<...> stuff is more involved...
[SVN r15097]
1 parent 5bcb901 commit f030618

4 files changed

Lines changed: 131 additions & 8 deletions

File tree

include/boost/python/detail/defaults_def.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include <boost/python/detail/defaults_gen.hpp>
1616
#include <boost/type_traits.hpp>
1717
#include <boost/mpl/int_t.hpp>
18-
#include <boost/mpl/size.hpp>
1918
#include <boost/static_assert.hpp>
2019
#include <boost/preprocessor/iterate.hpp>
20+
#include <boost/python/detail/type_list_utils.hpp>
2121

2222
///////////////////////////////////////////////////////////////////////////////
2323
namespace boost { namespace python {
@@ -134,7 +134,7 @@ struct define_stub_function {};
134134
SigT sig,
135135
char const* doc)
136136
{
137-
typedef typename mpl::at<0, SigT>::type nth_type;
137+
typedef typename boost::python::detail::type_at<0, SigT>::type nth_type;
138138
typedef typename StubsT::v_type v_type;
139139
typedef typename StubsT::nv_type nv_type;
140140

@@ -145,7 +145,8 @@ struct define_stub_function {};
145145
>::type stubs_type;
146146

147147
BOOST_STATIC_ASSERT(
148-
(stubs_type::max_args + 1) <= boost::mpl::size<SigT>::value);
148+
(stubs_type::max_args + 1) <=
149+
boost::python::detail::type_list_size<SigT>::value);
149150

150151
typedef typename stubs_type::template gen<SigT> gen_type;
151152
define_with_defaults_helper<stubs_type::n_funcs-1>::def

include/boost/python/detail/defaults_gen.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <boost/preprocessor/inc.hpp>
2222
#include <boost/preprocessor/empty.hpp>
2323
#include <boost/config.hpp>
24+
#include <boost/python/detail/type_list_utils.hpp>
2425

2526
namespace boost { namespace python { namespace detail {
2627

@@ -44,7 +45,7 @@ struct func_stubs_base {};
4445

4546
///////////////////////////////////////////////////////////////////////////////
4647
#define BPL_IMPL_TYPEDEF_GEN(INDEX, DATA) \
47-
typedef typename boost::mpl::at \
48+
typedef typename boost::python::detail::type_at \
4849
< \
4950
BOOST_PP_ADD(INDEX, DATA), \
5051
SigT \
@@ -84,7 +85,7 @@ struct func_stubs_base {};
8485
template <typename SigT> \
8586
struct gen { \
8687
\
87-
typedef typename boost::mpl::at<0, SigT>::type RT; \
88+
typedef typename boost::python::detail::type_at<0, SigT>::type RT; \
8889
\
8990
BOOST_PP_FIX_REPEAT_2ND \
9091
( \
@@ -135,8 +136,8 @@ struct func_stubs_base {};
135136
template <typename SigT> \
136137
struct gen { \
137138
\
138-
typedef typename boost::mpl::at<0, SigT>::type RT; \
139-
typedef typename boost::mpl::at<1, SigT>::type ClassT; \
139+
typedef typename boost::python::detail::type_at<0, SigT>::type RT; \
140+
typedef typename boost::python::detail::type_at<1, SigT>::type ClassT;\
140141
\
141142
BOOST_PP_FIX_REPEAT_2ND \
142143
( \
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright David Abrahams 2002. Permission to copy, use,
4+
// modify, sell and distribute this software is granted provided this
5+
// copyright notice appears in all copies. This software is provided
6+
// "as is" without express or implied warranty, and with no claim as
7+
// to its suitability for any purpose.
8+
//
9+
///////////////////////////////////////////////////////////////////////////////
10+
#if !defined(BOOST_PP_IS_ITERATING)
11+
12+
#ifndef TYPE_LIST_UTILS_JDG20020826_HPP
13+
#define TYPE_LIST_UTILS_JDG20020826_HPP
14+
15+
# include <boost/mpl/at.hpp>
16+
# include <boost/mpl/size.hpp>
17+
//# include <boost/mpl/pop_front.hpp>
18+
//# include <boost/mpl/pop_back.hpp>
19+
20+
# include <boost/preprocessor/enum_params.hpp>
21+
# include <boost/preprocessor/enum_shifted_params.hpp>
22+
# include <boost/preprocessor/cat.hpp>
23+
# include <boost/preprocessor/iterate.hpp>
24+
# include <boost/preprocessor/dec.hpp>
25+
26+
namespace boost { namespace python { namespace detail {
27+
28+
# if (!defined(__EDG_VERSION__) || __EDG_VERSION__ > 245) \
29+
&& (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600)
30+
31+
template <int N, class L>
32+
struct type_at : public boost::mpl::at<N, L> {};
33+
34+
template <class L>
35+
struct type_list_size : public boost::mpl::size<L> {};
36+
37+
// template <class L>
38+
// struct pop_front : public boost::mpl::pop_front<L> {};
39+
//
40+
// template <class L>
41+
// struct pop_back : public boost::mpl::pop_back<L> {};
42+
43+
# else
44+
45+
template <int N, class L>
46+
struct type_at {};
47+
48+
template <class L>
49+
struct type_list_size {};
50+
51+
// template <class L>
52+
// struct pop_front {};
53+
//
54+
// template <class L>
55+
// struct pop_back {};
56+
57+
// template <class L, class T>
58+
// struct push_back {};
59+
60+
# define BOOST_PP_ITERATION_PARAMS_1 \
61+
(3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/type_list_utils.hpp>))
62+
# include BOOST_PP_ITERATE()
63+
64+
# endif
65+
66+
}}} // namespace boost::python::detail
67+
68+
#endif // TYPE_LIST_UTILS_JDG20020826_HPP
69+
70+
#else // defined(BOOST_PP_IS_ITERATING)
71+
72+
# define N BOOST_PP_ITERATION()
73+
# define MAX BOOST_PYTHON_MAX_ARITY
74+
75+
# if (N < MAX-1)
76+
77+
template <BOOST_PP_ENUM_PARAMS(MAX, class A)>
78+
struct type_at<N, boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(MAX, A)> >
79+
{
80+
typedef BOOST_PP_CAT(A, N) type;
81+
};
82+
83+
// template <BOOST_PP_ENUM_PARAMS(N, class A) BOOST_PP_COMMA_IF(N) class T>
84+
// struct push_back<boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(N, A)>, T>
85+
// {
86+
// typedef boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(N, A) BOOST_PP_COMMA_IF(N) T> sequence;
87+
// };
88+
89+
# if (N > 0)
90+
91+
// template <BOOST_PP_ENUM_PARAMS(N, class A)>
92+
// struct pop_front<boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(N, A)> >
93+
// {
94+
// typedef boost::mpl::type_list<BOOST_PP_ENUM_SHIFTED_PARAMS(N, A)> sequence;
95+
// };
96+
//
97+
// template <BOOST_PP_ENUM_PARAMS(N, class A)>
98+
// struct pop_back<boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(N, A)> >
99+
// {
100+
// typedef boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(N), A)> sequence;
101+
// };
102+
103+
# endif
104+
# endif
105+
106+
template <BOOST_PP_ENUM_PARAMS(N, class A)>
107+
struct type_list_size<boost::mpl::type_list<BOOST_PP_ENUM_PARAMS(N, A)> >
108+
{
109+
BOOST_STATIC_CONSTANT(long, value = N);
110+
};
111+
112+
# undef N
113+
# undef MAX
114+
115+
#endif // !defined(BOOST_PP_IS_ITERATING)

test/defaults.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ BOOST_PYTHON_MODULE_INIT(defaults_ext)
121121
;
122122

123123
class_<X>("X")
124+
125+
# if (!defined(__EDG_VERSION__) || __EDG_VERSION__ > 245) \
126+
&& (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600)
124127
.def(init<int, optional<char, std::string, double> >())
125-
.def("get_state", &X::get_state)
128+
#endif
129+
130+
131+
.def("get_state", &X::get_state)
126132
.def("bar", &X::bar, X_bar_stubs())
127133
.def("foo", (object(X::*)(std::string, bool) const)0, X_foo_2_stubs())
128134
.def("foo", (object(X::*)(int, bool) const)0, X_foo_2_stubs())

0 commit comments

Comments
 (0)