Skip to content

Commit 09d5984

Browse files
committed
Improve MSVC compiler throughput by avoiding unneeded instantiations
1 parent 91a666b commit 09d5984

File tree

2 files changed

+20
-53
lines changed

2 files changed

+20
-53
lines changed

Release/include/cpprest/astreambuf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,4 +1200,5 @@ namespace streams
12001200
};
12011201

12021202
}}
1203+
12031204

Release/include/pplx/pplxtasks.h

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void cpprest_init(JavaVM*);
6060
#include <algorithm>
6161

6262
#if defined(_MSC_VER)
63+
#include <intrin.h>
6364
#if defined(__cplusplus_winrt)
6465
#include <windows.h>
6566
#include <ctxtcall.h>
@@ -6698,7 +6699,7 @@ auto when_all(_Iterator _Begin, _Iterator _End, const task_options& _TaskOptions
66986699
/// <seealso cref="Task Parallelism (Concurrency Runtime)"/>
66996700
/**/
67006701
template<typename _ReturnType>
6701-
task<std::vector<_ReturnType>> operator&&(const task<_ReturnType> & _Lhs, const task<_ReturnType> & _Rhs)
6702+
auto operator&&(const task<_ReturnType> & _Lhs, const task<_ReturnType> & _Rhs)
67026703
{
67036704
task<_ReturnType> _PTasks[2] = {_Lhs, _Rhs};
67046705
return when_all(_PTasks, _PTasks+2);
@@ -6730,7 +6731,7 @@ task<std::vector<_ReturnType>> operator&&(const task<_ReturnType> & _Lhs, const
67306731
/// <seealso cref="Task Parallelism (Concurrency Runtime)"/>
67316732
/**/
67326733
template<typename _ReturnType>
6733-
task<std::vector<_ReturnType>> operator&&(const task<std::vector<_ReturnType>> & _Lhs, const task<_ReturnType> & _Rhs)
6734+
auto operator&&(const task<std::vector<_ReturnType>> & _Lhs, const task<_ReturnType> & _Rhs)
67346735
{
67356736
return details::_WhenAllVectorAndValue(_Lhs, _Rhs, true);
67366737
}
@@ -6761,7 +6762,7 @@ task<std::vector<_ReturnType>> operator&&(const task<std::vector<_ReturnType>> &
67616762
/// <seealso cref="Task Parallelism (Concurrency Runtime)"/>
67626763
/**/
67636764
template<typename _ReturnType>
6764-
task<std::vector<_ReturnType>> operator&&(const task<_ReturnType> & _Lhs, const task<std::vector<_ReturnType>> & _Rhs)
6765+
auto operator&&(const task<_ReturnType> & _Lhs, const task<std::vector<_ReturnType>> & _Rhs)
67656766
{
67666767
return details::_WhenAllVectorAndValue(_Rhs, _Lhs, false);
67676768
}
@@ -6792,43 +6793,12 @@ task<std::vector<_ReturnType>> operator&&(const task<_ReturnType> & _Lhs, const
67926793
/// <seealso cref="Task Parallelism (Concurrency Runtime)"/>
67936794
/**/
67946795
template<typename _ReturnType>
6795-
task<std::vector<_ReturnType>> operator&&(const task<std::vector<_ReturnType>> & _Lhs, const task<std::vector<_ReturnType>> & _Rhs)
6796+
auto operator&&(const task<std::vector<_ReturnType>> & _Lhs, const task<std::vector<_ReturnType>> & _Rhs)
67966797
{
67976798
task<std::vector<_ReturnType>> _PTasks[2] = {_Lhs, _Rhs};
67986799
return when_all(_PTasks, _PTasks+2);
67996800
}
68006801

6801-
/// <summary>
6802-
/// Creates a task that will complete succesfully when both of the tasks supplied as arguments complete successfully.
6803-
/// </summary>
6804-
/// <typeparam name="_ReturnType">
6805-
/// The type of the returned task.
6806-
/// </typeparam>
6807-
/// <param name="_Lhs">
6808-
/// The first task to combine into the resulting task.
6809-
/// </param>
6810-
/// <param name="_Rhs">
6811-
/// The second task to combine into the resulting task.
6812-
/// </param>
6813-
/// <returns>
6814-
/// A task that completes successfully when both of the input tasks have completed successfully. If the input tasks are of type <c>T</c>,
6815-
/// the output of this function will be a <c>task&lt;std::vector&lt;T&gt;&gt;</c>. If the input tasks are of type <c>void</c> the output
6816-
/// task will also be a <c>task&lt;void&gt;</c>.
6817-
/// <para> To allow for a construct of the sort taskA &amp;&amp; taskB &amp;&amp; taskC, which are combined in pairs, the &amp;&amp; operator
6818-
/// produces a <c>task&lt;std::vector&lt;T&gt;&gt;</c> if either one or both of the tasks are of type <c>task&lt;std::vector&lt;T&gt;&gt;</c>.</para>
6819-
/// </returns>
6820-
/// <remarks>
6821-
/// If one of the tasks is canceled or throws an exception, the returned task will complete early, in the canceled state, and the exception,
6822-
/// if one is encoutered, will be thrown if you call <c>get()</c> or <c>wait()</c> on that task.
6823-
/// </remarks>
6824-
/// <seealso cref="Task Parallelism (Concurrency Runtime)"/>
6825-
/**/
6826-
inline task<void> operator&&(const task<void> & _Lhs, const task<void> & _Rhs)
6827-
{
6828-
task<void> _PTasks[2] = {_Lhs, _Rhs};
6829-
return when_all(_PTasks, _PTasks+2);
6830-
}
6831-
68326802
namespace details
68336803
{
68346804
// Helper struct for when_any operators to know when tasks have completed
@@ -7114,7 +7084,7 @@ auto when_any(_Iterator _Begin, _Iterator _End, cancellation_token _Cancellation
71147084
/// <seealso cref="Task Parallelism (Concurrency Runtime)"/>
71157085
/**/
71167086
template<typename _ReturnType>
7117-
task<_ReturnType> operator||(const task<_ReturnType> & _Lhs, const task<_ReturnType> & _Rhs)
7087+
auto operator||(const task<_ReturnType> & _Lhs, const task<_ReturnType> & _Rhs)
71187088
{
71197089
auto _PParam = new details::_RunAnyParam<std::pair<_ReturnType, size_t>>();
71207090

@@ -7175,7 +7145,7 @@ task<_ReturnType> operator||(const task<_ReturnType> & _Lhs, const task<_ReturnT
71757145
/// <seealso cref="Task Parallelism (Concurrency Runtime)"/>
71767146
/**/
71777147
template<typename _ReturnType>
7178-
task<std::vector<_ReturnType>> operator||(const task<std::vector<_ReturnType>> & _Lhs, const task<_ReturnType> & _Rhs)
7148+
auto operator||(const task<std::vector<_ReturnType>> & _Lhs, const task<_ReturnType> & _Rhs)
71797149
{
71807150
auto _PParam = new details::_RunAnyParam<std::pair<std::vector<_ReturnType>, details::_CancellationTokenState *>>();
71817151

@@ -7249,7 +7219,7 @@ task<std::vector<_ReturnType>> operator||(const task<std::vector<_ReturnType>> &
72497219
/// <seealso cref="Task Parallelism (Concurrency Runtime)"/>
72507220
/**/
72517221
template<typename _ReturnType>
7252-
task<std::vector<_ReturnType>> operator||(const task<_ReturnType> & _Lhs, const task<std::vector<_ReturnType>> & _Rhs)
7222+
auto operator||(const task<_ReturnType> & _Lhs, const task<std::vector<_ReturnType>> & _Rhs)
72537223
{
72547224
return _Rhs || _Lhs;
72557225
}
@@ -7280,14 +7250,17 @@ task<std::vector<_ReturnType>> operator||(const task<_ReturnType> & _Lhs, const
72807250
/// </remarks>
72817251
/// <seealso cref="Task Parallelism (Concurrency Runtime)"/>
72827252
/**/
7283-
inline task<void> operator||(const task<void> & _Lhs, const task<void> & _Rhs)
7253+
template<typename _Ty = task<void>, typename _Pair = std::pair<details::_Unit_type, details::_CancellationTokenState *>>
7254+
_Ty operator||(const task<void> & _Lhs_arg, const task<void> & _Rhs_arg)
72847255
{
7285-
auto _PParam = new details::_RunAnyParam<std::pair<details::_Unit_type, details::_CancellationTokenState *>>();
7256+
const _Ty& _Lhs = _Lhs_arg;
7257+
const _Ty& _Rhs = _Rhs_arg;
7258+
auto _PParam = new details::_RunAnyParam<_Pair>();
72867259

72877260
task<std::pair<details::_Unit_type, details::_CancellationTokenState *>> _Any_task_completed(_PParam->_M_Completed, _PParam->_M_cancellationSource.get_token());
72887261
// Chain the return continuation task here to ensure it will get inline execution when _M_Completed.set is called,
72897262
// So that _PParam can be used before it getting deleted.
7290-
auto _ReturnTask = _Any_task_completed._Then([=](std::pair<details::_Unit_type, details::_CancellationTokenState *> _Ret) {
7263+
auto _ReturnTask = _Any_task_completed._Then([=](_Pair _Ret) {
72917264
_ASSERTE(_Ret.second);
72927265
details::_JoinAllTokens_Add(_PParam->_M_cancellationSource, _Ret.second);
72937266
}, nullptr);
@@ -7298,7 +7271,7 @@ inline task<void> operator||(const task<void> & _Lhs, const task<void> & _Rhs)
72987271
}
72997272

73007273
_PParam->_M_numTasks = 2;
7301-
auto _Continuation = [_PParam](task<void> _ResultTask) mutable {
7274+
auto _Continuation = [_PParam](_Ty _ResultTask) mutable {
73027275
// Dev10 compiler needs this.
73037276
auto _PParam1 = _PParam;
73047277
auto _Func = [&_ResultTask, _PParam1]() {
@@ -7321,18 +7294,10 @@ task<_Ty> task_from_result(_Ty _Param, const task_options& _TaskOptions = task_o
73217294
return create_task(_Tce, _TaskOptions);
73227295
}
73237296

7324-
// Work around VS 2010 compiler bug
7325-
#if _MSC_VER == 1600
7326-
inline task<bool> task_from_result(bool _Param)
7327-
{
7328-
task_completion_event<bool> _Tce;
7329-
_Tce.set(_Param);
7330-
return create_task(_Tce, task_options());
7331-
}
7332-
#endif
7333-
inline task<void> task_from_result(const task_options& _TaskOptions = task_options())
7297+
template<class _Ty = void>
7298+
inline task<_Ty> task_from_result(const task_options& _TaskOptions = task_options())
73347299
{
7335-
task_completion_event<void> _Tce;
7300+
task_completion_event<_Ty> _Tce;
73367301
_Tce.set();
73377302
return create_task(_Tce, _TaskOptions);
73387303
}
@@ -7367,3 +7332,4 @@ namespace concurrency = Concurrency;
73677332
#endif
73687333

73697334
#endif // _PPLXTASKS_H
7335+

0 commit comments

Comments
 (0)