44
55namespace
66{
7- static const rtl::CxxMirror& cxx_mirror ()
8- {
9- static auto m = rtl::CxxMirror ({
7+ static rtl::RObject nodeObj;
8+ static rtl::Method NodeGetMessage;
9+ static rtl::Method NodeSendMessage;
10+ static rtl::Function GetMessage;
11+ static rtl::Function SendMessage;
12+
13+ static auto _= []() {
14+
15+ rtl::CxxMirror m = rtl::CxxMirror ({
1016
1117 rtl::type ().function (" getMessage" ).build (bm::getMessage),
1218
@@ -18,24 +24,22 @@ namespace
1824
1925 rtl::type ().member <bm::Node>().method (" getMessage" ).build (&bm::Node::getMessage)
2026 });
21- return m;
22- }
23-
24- static rtl::Record Node = cxx_mirror().getRecord(" Node" ).value();
25-
26- static rtl::RObject robj = Node.create<rtl::alloc::Stack>().rObject;
2727
28- static rtl::Method NodeGetMessage = Node.getMethod (" getMessage" ).value();
29-
30- static rtl::Method NodeSendMessage = Node.getMethod (" sendMessage" ).value();
28+ GetMessage = m. getFunction (" getMessage" ).value ();
29+
30+ SendMessage = m. getFunction (" sendMessage" ).value ();
3131
32- static rtl::Function GetMessage = cxx_mirror().getFunction( " getMessage " ).value();
32+ rtl::Record Node = m. getRecord ( " Node " ).value ();
3333
34- static rtl::Function SendMessage = cxx_mirror().getFunction(" sendMessage" ).value();
34+ nodeObj = std::move (Node.create <rtl::alloc::Stack>().rObject );
35+
36+ NodeGetMessage = Node.getMethod (" getMessage" ).value ();
37+ NodeSendMessage = Node.getMethod (" sendMessage" ).value ();
38+ return true ;
39+ }();
3540}
3641
3742
38-
3943 namespace
4044 {
4145 static auto _test0 = []()
@@ -50,7 +54,7 @@ namespace
5054
5155 static auto _test1 = []()
5256 {
53- auto err = NodeSendMessage (robj )(bm::g_longStr).err ;
57+ auto err = NodeSendMessage (nodeObj )(bm::g_longStr).err ;
5458
5559 if (err != rtl::error::None) {
5660 std::cout << " [1] error: " << rtl::to_string (err) << " \n " ;
@@ -70,7 +74,7 @@ namespace
7074
7175 static auto _test3 = []()
7276 {
73- auto err = NodeGetMessage (robj )(bm::g_longStr).err ;
77+ auto err = NodeGetMessage (nodeObj )(bm::g_longStr).err ;
7478
7579 if (err != rtl::error::None) {
7680 std::cout << " [3] error: " << rtl::to_string (err) << " \n " ;
@@ -86,7 +90,7 @@ void ReflectedCall::noReturn(benchmark::State& state)
8690 static auto _=_test0 ();
8791 for (auto _: state) {
8892
89- auto error = SendMessage. bind (). call (bm::g_longStr).err ;
93+ auto error = SendMessage (bm::g_longStr).err ;
9094 benchmark::DoNotOptimize (error);
9195 }
9296}
@@ -97,7 +101,7 @@ void ReflectedCall::withReturn(benchmark::State& state)
97101 static auto _=_test2 ();
98102 for (auto _: state)
99103 {
100- auto error = GetMessage. bind (). call (bm::g_longStr).err ;
104+ auto error = GetMessage (bm::g_longStr).err ;
101105 benchmark::DoNotOptimize (error);
102106 }
103107}
@@ -108,7 +112,7 @@ void ReflectedMethodCall::noReturn(benchmark::State& state)
108112 static auto _=_test1 ();
109113 for (auto _: state)
110114 {
111- auto error = NodeSendMessage. bind (robj). call (bm::g_longStr).err ;
115+ auto error = NodeSendMessage (nodeObj) (bm::g_longStr).err ;
112116 benchmark::DoNotOptimize (error);
113117 }
114118}
@@ -119,7 +123,7 @@ void ReflectedMethodCall::withReturn(benchmark::State& state)
119123 static auto _=_test3 ();
120124 for (auto _: state)
121125 {
122- auto error = NodeGetMessage. bind (robj). call (bm::g_longStr).err ;
126+ auto error = NodeGetMessage (nodeObj) (bm::g_longStr).err ;
123127 benchmark::DoNotOptimize (error);
124128 }
125129}
0 commit comments