Skip to content

Commit aee3f63

Browse files
CJCombrinkJens-G
authored andcommitted
THRIFT-5817: [C++] Avoid copy of TUuid
Client: cpp Patch: Carel Combrink This closes #3038
1 parent fdaca5e commit aee3f63

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

compiler/cpp/src/thrift/generate/t_cpp_generator.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,12 @@ class t_cpp_generator : public t_oop_generator {
274274
bool is_complex_type(t_type* ttype) {
275275
ttype = get_true_type(ttype);
276276

277-
return ttype->is_container() || ttype->is_struct() || ttype->is_xception()
277+
return ttype->is_container() //
278+
|| ttype->is_struct() //
279+
|| ttype->is_xception()
278280
|| (ttype->is_base_type()
279-
&& (((t_base_type*)ttype)->get_base() == t_base_type::TYPE_STRING));
281+
&& ((((t_base_type*)ttype)->get_base() == t_base_type::TYPE_STRING)
282+
|| (((t_base_type*)ttype)->get_base() == t_base_type::TYPE_UUID)));
280283
}
281284

282285
void set_use_include_prefix(bool use_include_prefix) { use_include_prefix_ = use_include_prefix; }
@@ -4498,7 +4501,7 @@ string t_cpp_generator::type_name(t_type* ttype, bool in_typedef, bool arg) {
44984501
return bname;
44994502
}
45004503

4501-
if (((t_base_type*)ttype)->get_base() == t_base_type::TYPE_STRING) {
4504+
if ((((t_base_type*)ttype)->get_base() == t_base_type::TYPE_STRING) || ((((t_base_type*)ttype)->get_base() == t_base_type::TYPE_UUID))) {
45024505
return "const " + bname + "&";
45034506
} else {
45044507
return "const " + bname;

lib/c_glib/test/testthrifttestclient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ class TestHandler : public ThriftTestIf {
112112
out = thing;
113113
}
114114

115-
apache::thrift::TUuid testUuid(const apache::thrift::TUuid thing) override {
115+
void testUuid(apache::thrift::TUuid& out, const apache::thrift::TUuid& thing) override {
116116
cout << "[C -> C++] testUuid(\"" << thing << "\")" << '\n';
117-
return thing;
117+
out = thing;
118118
}
119119

120120
void testStruct(Xtruct& out, const Xtruct &thing) override {

lib/c_glib/test/testthrifttestzlibclient.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ class TestHandler : public ThriftTestIf {
107107
out = thing;
108108
}
109109

110-
apache::thrift::TUuid testUuid(const apache::thrift::TUuid thing) override {
110+
void testUuid(apache::thrift::TUuid& out, const apache::thrift::TUuid& thing) override {
111111
cout << "[C -> C++] testUuid(\"" << thing << "\")" << '\n';
112-
return thing;
112+
out = thing;
113113
}
114114

115115
void testStruct(Xtruct& out, const Xtruct &thing) override {
@@ -297,7 +297,7 @@ class TestHandler : public ThriftTestIf {
297297
}
298298

299299
void testException(const std::string &arg)
300-
throw(Xception, apache::thrift::TException) override
300+
noexcept(false) override
301301
{
302302
cout << "[C -> C++] testException(" << arg << ")" << '\n';
303303
if (arg.compare("Xception") == 0) {
@@ -315,7 +315,7 @@ class TestHandler : public ThriftTestIf {
315315
}
316316
}
317317

318-
void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) override {
318+
void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) noexcept(false) override {
319319

320320
cout << "[C -> C++] testMultiException(" << arg0 << ", " << arg1 << ")" << '\n';
321321

test/cpp/src/TestClient.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ bool print_eq(T expected, T actual) {
181181
#define UUID_TEST(func, value, expected) \
182182
cout << #func "(" << value << ") = "; \
183183
try { \
184-
if (!print_eq(expected, testClient.func(value))) \
184+
TUuid ret; \
185+
testClient.func(ret, value); \
186+
if (!print_eq(expected, ret)) \
185187
return_code |= ERR_BASETYPES; \
186188
} catch (TTransportException&) { \
187189
throw; \

test/cpp/src/TestServer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ class TestHandler : public ThriftTestIf {
132132
_return = thing;
133133
}
134134

135-
TUuid testUuid(const TUuid thing) override {
135+
void testUuid(apache::thrift::TUuid& _return, const apache::thrift::TUuid& thing) override {
136136
printf("testUuid(\"{%s}\")\n", to_string(thing).c_str());
137-
return thing;
137+
_return = thing;
138138
}
139139

140140
void testStruct(Xtruct& out, const Xtruct& thing) override {
@@ -447,8 +447,9 @@ class TestHandlerAsync : public ThriftTestCobSvIf {
447447
cob(res);
448448
}
449449

450-
void testUuid(::std::function<void(TUuid const& _return)> cob, const TUuid thing) override {
451-
TUuid res = _delegate->testUuid(thing);
450+
void testUuid(::std::function<void(apache::thrift::TUuid const& _return)> cob, const apache::thrift::TUuid& thing) override {
451+
TUuid res;
452+
_delegate->testUuid(res, thing);
452453
cob(res);
453454
}
454455

0 commit comments

Comments
 (0)