Skip to content

Commit 891e7ab

Browse files
committed
removed unnecessory try-catch.
1 parent 214085c commit 891e7ab

File tree

7 files changed

+128
-103
lines changed

7 files changed

+128
-103
lines changed

RTLBenchmarkApp/src/BenchMark.cpp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include <any>
2+
33
#include <optional>
44

55
#include <iostream>
@@ -8,11 +8,12 @@
88

99
namespace {
1010

11-
static const char* LONG_STR = "Lorem ipsum";// dolor sit amet, consectetur adipiscing elit, sed do";
11+
static const char* LONG_STR = "Lorem ipsum";// dolor sit amet, consectetur adipiscing elit, sed do"
1212
//"do aeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis"
1313
//"nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure"
1414
//"dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Except"
15-
//"eur ssint occaecat cupidatat nnon proident, sunt in culpa qui officia deserunt mollit anim id";
15+
//"eur ssint occaecat cupidatat nnon proident, sunt in culpa qui officia deserunt mollit anim id"
16+
//"Lorem ipsum dolor sit amet laboris nisi ut aliquip ex ea commodo";
1617
}
1718

1819
// Pre-created string to isolate call overhead
@@ -44,6 +45,21 @@ namespace rtl_bench
4445
}
4546

4647

48+
void BenchMark::stdFunctionMethodCall_noReturn(benchmark::State& state)
49+
{
50+
Node* node = new Node();
51+
static std::function sendMsg = [=](argStr_t& pMsg) {
52+
node->sendMessage(pMsg);
53+
};
54+
55+
for (auto _ : state)
56+
{
57+
sendMsg(g_longStr);
58+
benchmark::DoNotOptimize(g_msg);
59+
}
60+
}
61+
62+
4763
void BenchMark::directCall_withReturn(benchmark::State& state)
4864
{
4965
static auto _ = []() {
@@ -62,9 +78,21 @@ namespace rtl_bench
6278
void BenchMark::stdFunctionCall_withReturn(benchmark::State& state)
6379
{
6480
static std::function getMsg = [](argStr_t& pMsg) {
65-
retStr_t retMsg = getMessage(pMsg);
66-
volatile auto *msg = &retMsg;
67-
return retMsg;
81+
return getMessage(pMsg);
82+
};
83+
84+
for (auto _ : state)
85+
{
86+
benchmark::DoNotOptimize(getMsg(g_longStr));
87+
}
88+
}
89+
90+
91+
void BenchMark::stdFunctionMethodCall_withReturn(benchmark::State& state)
92+
{
93+
static Node* node = new Node();
94+
static std::function getMsg = [=](argStr_t& pMsg) {
95+
return node->getMessage(pMsg);
6896
};
6997

7098
for (auto _ : state)
@@ -99,7 +127,7 @@ namespace rtl_bench
99127
{
100128
static rtl::Record rNode = cxx_mirror().getRecord("Node").value();
101129
static rtl::Method sendMsg = rNode.getMethod("sendMessage").value();
102-
static rtl::RObject robj = rNode.create<rtl::alloc::Stack>().rObject;
130+
static rtl::RObject robj = rNode.create<rtl::alloc::Heap>().rObject;
103131
static auto _ = []() {
104132
auto err = sendMsg.bind(robj).call(g_longStr).err;
105133
if (err != rtl::error::None) {

RTLBenchmarkApp/src/BenchMark.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,16 @@ namespace rtl_bench
6868

6969
static void reflectedCall_noReturn(benchmark::State& state);
7070

71+
static void stdFunctionMethodCall_noReturn(benchmark::State& state);
72+
7173
static void reflectedMethodCall_noReturn(benchmark::State& state);
7274

7375
static void directCall_withReturn(benchmark::State& state);
7476

7577
static void stdFunctionCall_withReturn(benchmark::State& state);
7678

79+
static void stdFunctionMethodCall_withReturn(benchmark::State& state);
80+
7781
static void reflectedCall_withReturn(benchmark::State& state);
7882

7983
static void reflectedMethodCall_withReturn(benchmark::State& state);

RTLBenchmarkApp/src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
BENCHMARK(rtl_bench::BenchMark::directCall_noReturn);
99
BENCHMARK(rtl_bench::BenchMark::stdFunctionCall_noReturn);
10+
BENCHMARK(rtl_bench::BenchMark::stdFunctionMethodCall_noReturn);
1011
BENCHMARK(rtl_bench::BenchMark::reflectedCall_noReturn);
1112
BENCHMARK(rtl_bench::BenchMark::reflectedMethodCall_noReturn);
1213

1314
BENCHMARK(rtl_bench::BenchMark::directCall_withReturn);
1415
BENCHMARK(rtl_bench::BenchMark::stdFunctionCall_withReturn);
16+
BENCHMARK(rtl_bench::BenchMark::stdFunctionMethodCall_withReturn);
1517
BENCHMARK(rtl_bench::BenchMark::reflectedCall_withReturn);
1618
BENCHMARK(rtl_bench::BenchMark::reflectedMethodCall_withReturn);
1719

RTLTestRunApp/src/FunctionalityTests/MoveConstructorTests.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using namespace std;
88
using namespace rtl;
99

10-
using namespace test_utils;
10+
using namespace test_utils;
1111
using namespace test_mirror;
1212

1313
namespace rtl_tests
@@ -38,7 +38,7 @@ namespace rtl_tests
3838

3939
// Moving a RObject created via alloc::Stack, invokes Calender's move constructor.
4040
RObject calender1 = std::move(calender0);
41-
41+
4242
//TODO: Fails on linux, differently optimized away from windows?
4343
// Calender's move-constructor called once.
4444
// EXPECT_TRUE(calender::get_move_ops_count() == 1);
@@ -49,6 +49,7 @@ namespace rtl_tests
4949

5050
// 'calander0' must be empty now.
5151
ASSERT_TRUE(calender0.isEmpty());
52+
EXPECT_NE(calender0.getTypeId(), calender1.getTypeId());
5253

5354
// After move, these instance count must remain same.
5455
EXPECT_TRUE(calender::get_instance_count() == 1);
@@ -113,6 +114,7 @@ namespace rtl_tests
113114

114115
// 'calander0' must be empty now.
115116
ASSERT_TRUE(calender0.isEmpty());
117+
EXPECT_NE(calender0.getTypeId(), calender1.getTypeId());
116118

117119
// After move, these instance count must remain same.
118120
EXPECT_TRUE(calender::get_instance_count() == 1);
@@ -182,6 +184,7 @@ namespace rtl_tests
182184

183185
// 'event0' must be empty now.
184186
ASSERT_TRUE(event0.isEmpty());
187+
EXPECT_NE(event0.getTypeId(), event1.getTypeId());
185188
{
186189
// Event::reset() is a non-const method. can't be called on const-object.
187190
optional<Method> eventReset = classEvent->getMethod(event::str_reset);
@@ -244,7 +247,7 @@ namespace rtl_tests
244247
// Moving a RObject created via alloc::Stack, invokes Calender's move constructor.
245248
RObject calender1 = std::move(calender0);
246249

247-
//TODO: Fails on linux, differently optimized away from windows?
250+
//TODO: Works on windows, fails on linux, differently optimized away for windows?
248251
// Calender's move-constructor called once.
249252
// EXPECT_TRUE(calender::get_move_ops_count() == 1);
250253

@@ -254,6 +257,7 @@ namespace rtl_tests
254257

255258
// 'calander0' must be empty now.
256259
ASSERT_TRUE(calender0.isEmpty());
260+
EXPECT_NE(calender0.getTypeId(), calender1.getTypeId());
257261

258262
// After move, these instance count must remain same.
259263
EXPECT_TRUE(calender::get_instance_count() == 1);

ReflectionTemplateLib/access/inc/RObject.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ namespace rtl
4343
{
4444
using Cloner = std::function< Return(const RObject&, rtl::alloc) >;
4545

46-
mutable std::any m_object;
47-
mutable detail::RObjectId m_objectId;
46+
std::any m_object;
47+
detail::RObjectId m_objectId;
4848

49-
mutable const Cloner* m_getClone;
50-
mutable const std::vector<traits::ConverterPair>* m_converters;
49+
const Cloner* m_getClone = nullptr;
50+
const std::vector<traits::ConverterPair>* m_converters = nullptr;
5151

5252
RObject(const RObject&) = default;
5353
RObject(std::any&& pObject, const detail::RObjectId pRObjId, const Cloner* pCloner,

ReflectionTemplateLib/access/inc/RObject.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ namespace rtl
2626
{
2727
FORCE_INLINE RObject::RObject(std::any&& pObject, const detail::RObjectId pRObjId, const Cloner* pCloner,
2828
const std::vector<traits::ConverterPair>* pConverters) noexcept
29-
: m_object(std::forward<std::any>(pObject))
29+
: m_object(std::move(pObject))
3030
, m_objectId(pRObjId)
3131
, m_getClone(pCloner)
3232
, m_converters(pConverters)
3333
{ }
3434

35-
FORCE_INLINE RObject::RObject(RObject&& pOther) noexcept
35+
inline RObject::RObject(RObject&& pOther) noexcept
3636
: m_object(std::move(pOther.m_object))
3737
, m_objectId(pOther.m_objectId)
3838
, m_getClone(pOther.m_getClone)
@@ -101,7 +101,7 @@ namespace rtl
101101

102102

103103
template <class T, std::enable_if_t<traits::is_unique_ptr_v<T>, int>>
104-
std::optional<rtl::view<T>> RObject::view() const
104+
FORCE_INLINE std::optional<rtl::view<T>> RObject::view() const
105105
{
106106
if constexpr (traits::is_bare_type<T>())
107107
{
@@ -117,22 +117,24 @@ namespace rtl
117117

118118

119119
template <class T, std::enable_if_t<traits::is_shared_ptr_v<T>, int>>
120-
std::optional<rtl::view<T>> RObject::view() const
120+
FORCE_INLINE std::optional<rtl::view<T>> RObject::view() const
121121
{
122122
if constexpr (traits::is_bare_type<T>())
123123
{
124124
if (detail::TypeId<T>::get() == m_objectId.m_wrapperTypeId)
125125
{
126-
const T& sptrRef = *(detail::RObjExtractor(this).getWrapper<T>());
127-
return std::optional<rtl::view<T>>(std::in_place, const_cast<T&>(sptrRef));
126+
const T* sptrRef = detail::RObjExtractor(this).getWrapper<T>();
127+
if (sptrRef != nullptr) {
128+
return std::optional<rtl::view<T>>(std::in_place, const_cast<T&>(*sptrRef));
129+
}
128130
}
129131
}
130132
return std::nullopt;
131133
}
132134

133135

134136
template <class T, std::enable_if_t<traits::is_not_any_wrapper_v<T>, int>>
135-
inline std::optional<rtl::view<T>> RObject::view() const
137+
FORCE_INLINE std::optional<rtl::view<T>> RObject::view() const
136138
{
137139
if constexpr (traits::is_bare_type<T>())
138140
{

0 commit comments

Comments
 (0)