Change return-type of method ReadString to improve performance 62/162062/1
authorJunghoon Park <jh9216.park@samsung.com>
Wed, 29 Nov 2017 02:03:35 +0000 (11:03 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Wed, 29 Nov 2017 02:03:35 +0000 (11:03 +0900)
Change-Id: I34557a85d7458b47873e725fe533b36043239dc6
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
src/parcel-internal.cc
src/parcel-internal.h
src/rpc-port-parcel.cc
unit_tests/src/rpc_port_parcel_test.cc

index 2f1ce25..e09b614 100644 (file)
@@ -65,6 +65,7 @@ void Parcel::WriteBundle(bundle* b) {
 
   Write<int>(len + 1);
   std::copy(c, c + len + 1, std::back_inserter(data_));
+  free(r);
 }
 
 void Parcel::WriteArrayCount(int count) {
@@ -95,10 +96,10 @@ double Parcel::ReadDouble() {
   return Read<double>();
 }
 
-std::string Parcel::ReadString() {
+const char* Parcel::ReadString() {
   int l = Read<int>();
 
-  std::string str(reinterpret_cast<const char*>(&data_[reader_]));
+  const char* str = reinterpret_cast<const char*>(&data_[reader_]);
   reader_ += l;
 
   return str;
@@ -111,11 +112,10 @@ bool Parcel::ReadBool() {
 bundle* Parcel::ReadBundle() {
   int l = Read<int>();
 
-  std::string str(reinterpret_cast<const char*>(&data_[reader_]));
+  const bundle_raw* str = reinterpret_cast<const bundle_raw*>(&data_[reader_]);
   reader_ += l;
 
-  bundle* b = bundle_decode(
-      reinterpret_cast<const bundle_raw*>(str.c_str()), l - 1);
+  bundle* b = bundle_decode(str, l - 1);
 
   return b;
 }
index 43a7819..86f8e52 100644 (file)
@@ -47,7 +47,7 @@ class Parcel {
   long long ReadInt64();
   float ReadFloat();
   double ReadDouble();
-  std::string ReadString();
+  const char* ReadString();
   bool ReadBool();
   bundle* ReadBundle();
   int ReadArrayCount();
index 0500268..edc88a8 100755 (executable)
@@ -281,7 +281,7 @@ RPC_API int rpc_port_parcel_read_string(rpc_port_parcel_h h, char** str) {
 
   Parcel* p = static_cast<Parcel*>(h);
 
-  *str = strdup(p->ReadString().c_str());
+  *str = strdup(p->ReadString());
 
   return 0;
 }
index ee8d43c..12384c0 100644 (file)
@@ -60,6 +60,7 @@ class ParcelTest : public ::testing::Test {
     int ret = rpc_port_parcel_read_string(h, &s);
     ASSERT_EQ(ret, 0);
     ASSERT_STREQ(s, "abcdef");
+    free(s);
 
     double b;
     ret = rpc_port_parcel_read_double(h, &b);