Skip to content

Commit ded495c

Browse files
committed
refactor
1 parent 524adff commit ded495c

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

RTLBenchmarkApp/src/BenchMark.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,16 @@ namespace rtl_bench
118118

119119
void BenchMark::BM_LambdaFunc(benchmark::State& state)
120120
{
121-
static rtl::detail::LambdaFunction<const std::string> obj;
122-
121+
static rtl::detail::LambdaFunction<str_type, str_type> obj;
122+
static str_type str = std::string_view(g_longStr.c_str());
123123
static auto _ = []() {
124124
obj.init(getMessage);
125125
return 0;
126126
}();
127127

128128
for (auto _ : state) {
129-
benchmark::DoNotOptimize(obj(g_longStr));
129+
130+
benchmark::DoNotOptimize(obj(str));
130131
}
131132
}
132133
}

RTLBenchmarkApp/src/BenchMark.h

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#include "RTLibInterface.h"
66

7-
#include <streambuf>
8-
97
#if defined(_MSC_VER)
108
# define NOINLINE __declspec(noinline)
119
#elif defined(__GNUC__)
@@ -14,44 +12,43 @@
1412
# define NOINLINE
1513
#endif
1614

17-
using str_type = std::string; //*/ std::string_view;
15+
using str_type = /*std::string; //*/ std::string_view;
1816

1917
namespace rtl_bench
2018
{
2119
static std::optional<std::string> g_msg;
2220

2321
NOINLINE static void sendMessage(str_type pMsg) {
24-
std::string result = pMsg + pMsg;
25-
result = result + result;
26-
result = result + result;
22+
// std::string result = pMsg + pMsg;
23+
// result = result + result;
24+
// result = result + result;
2725
g_msg = pMsg;
2826
}
2927

3028
NOINLINE static str_type getMessage(str_type pMsg) {
31-
std::string result = pMsg + pMsg;
32-
result = result + result;
33-
result = result + result;
29+
// std::string result = pMsg + pMsg;
30+
// result = result + result;
31+
// result = result + result;
3432
g_msg = pMsg;
35-
return str_type(pMsg);
33+
return str_type(g_msg->c_str());
3634
}
3735

3836
struct Node
3937
{
4038
NOINLINE void sendMessage(str_type pMsg) {
41-
std::string result = pMsg + pMsg;
42-
result = result + result;
43-
result = result + result;
44-
g_msg = pMsg;
39+
// std::string result = pMsg + pMsg;
40+
// result = result + result;
41+
// result = result + result;
4542
g_msg = pMsg;
4643
}
4744

4845
NOINLINE str_type getMessage(str_type pMsg)
4946
{
50-
std::string result = pMsg + pMsg;
51-
result = result + result;
52-
result = result + result;
47+
// std::string result = pMsg + pMsg;
48+
// result = result + result;
49+
// result = result + result;
5350
g_msg = pMsg;
54-
return pMsg;
51+
return str_type(g_msg->c_str());
5552
}
5653
};
5754

ReflectionTemplateLib/detail/inc/LambdaFunction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace rtl::detail
66
{
7-
template<class... _signature>
7+
template<class _retT, class... _signature>
88
struct LambdaFunction
99
{
10-
using Invoker = std::string(*)(void* , _signature&...);
10+
using Invoker = _retT(*)(void* , _signature&...);
1111

1212
Invoker m_invoker = nullptr;
1313
void* m_storage = nullptr;
@@ -26,14 +26,14 @@ namespace rtl::detail
2626
static auto holder = Holder{ pFunctor };
2727
m_storage = &holder;
2828

29-
m_invoker = +[](void* stor, _signature&... params) -> std::string {
29+
m_invoker = +[](void* stor, _signature&... params) -> _retT {
3030

3131
auto h = static_cast<Holder*>(stor);
3232
return (h->m_functor)(params...);
3333
};
3434
}
3535

36-
std::string operator()(_signature&... params)
36+
_retT operator()(_signature&... params)
3737
{
3838
return m_invoker(m_storage, params...);
3939
}

0 commit comments

Comments
 (0)