[glibmm/glibmm-2-62] Avoid unnecessary conversions between std::string and Glib::ustring



commit 7de499b0e24e479bcebc82ba43026efd4619afd4
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Mon Nov 18 15:22:38 2019 +0100

    Avoid unnecessary conversions between std::string and Glib::ustring
    
    A few implicit conversions in tests/ have been kept. They are probably
    deliberate, to test implicit conversion. Inspired by issue #65

 examples/dbus/server_without_bus.cc   |  4 ++--
 examples/network/resolver.cc          | 18 ++++++++----------
 examples/options/main.cc              |  2 +-
 glib/src/checksum.ccg                 |  2 +-
 tests/giomm_memoryinputstream/main.cc |  2 +-
 5 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/examples/dbus/server_without_bus.cc b/examples/dbus/server_without_bus.cc
index 8b84bf54..dda068ca 100644
--- a/examples/dbus/server_without_bus.cc
+++ b/examples/dbus/server_without_bus.cc
@@ -113,7 +113,7 @@ on_server_new_connection(const Glib::RefPtr<Gio::DBus::Connection>& connection)
 {
   auto credentials = connection->get_peer_credentials();
 
-  std::string credentials_str;
+  Glib::ustring credentials_str;
 
   if (!credentials)
     credentials_str = "(no credentials received)";
@@ -176,7 +176,7 @@ main(int, char**)
 
   Glib::RefPtr<Gio::DBus::Server> server;
 
-  const Glib::ustring address = "unix:abstract=myadd";
+  const std::string address = "unix:abstract=myadd";
   try
   {
     server = Gio::DBus::Server::create_sync(address, Gio::DBus::generate_guid());
diff --git a/examples/network/resolver.cc b/examples/network/resolver.cc
index 5aedb635..0f16cdbe 100644
--- a/examples/network/resolver.cc
+++ b/examples/network/resolver.cc
@@ -349,12 +349,12 @@ do_async_connectable(Glib::RefPtr<Gio::SocketAddressEnumerator> enumerator)
 Glib::RefPtr<Gio::SocketConnectable> global_connectable;
 
 static void
-do_connectable(const std::string& arg, gboolean synchronous)
+do_connectable(const Glib::ustring& arg, gboolean synchronous)
 {
   std::vector<Glib::ustring> parts;
   Glib::RefPtr<Gio::SocketConnectable> connectable;
 
-  if (arg.find('/') != std::string::npos)
+  if (arg.find('/') != Glib::ustring::npos)
   {
     /* service/protocol/domain */
     parts = split_service_parts(arg);
@@ -368,18 +368,16 @@ do_connectable(const std::string& arg, gboolean synchronous)
   }
   else
   {
-    std::string host, port_str;
-    guint16 port;
+    Glib::ustring host;
+    guint16 port = 0;
 
     const auto pos = arg.find(':');
-    if (pos != std::string::npos)
+    if (pos != Glib::ustring::npos)
     {
       host = arg.substr(0, pos);
-      port_str = arg.substr(pos);
-      port = std::stoul(port_str);
+      auto port_str = arg.substr(pos);
+      port = std::stoul(port_str.raw());
     }
-    else
-      port = 0;
 
     if (Gio::hostname_is_ip_address(host))
     {
@@ -387,7 +385,7 @@ do_connectable(const std::string& arg, gboolean synchronous)
       connectable = Gio::InetSocketAddress::create(addr, port);
     }
     else
-      connectable = Gio::NetworkAddress::create(arg, port);
+      connectable = Gio::NetworkAddress::create(arg.raw(), port);
   }
 
   const auto enumerator = connectable->enumerate();
diff --git a/examples/options/main.cc b/examples/options/main.cc
index c4536cdf..6e6bfe1a 100644
--- a/examples/options/main.cc
+++ b/examples/options/main.cc
@@ -43,7 +43,7 @@ public:
   Glib::OptionGroup::vecustrings m_arg_list;
   Glib::OptionGroup::vecustrings m_remaining_list;
   Glib::ustring m_arg_x_string;
-  std::string m_arg_x_filename;
+  Glib::ustring m_arg_x_filename;
 };
 
 ExampleOptionGroup::ExampleOptionGroup()
diff --git a/glib/src/checksum.ccg b/glib/src/checksum.ccg
index f83810c6..be5f9e23 100644
--- a/glib/src/checksum.ccg
+++ b/glib/src/checksum.ccg
@@ -38,7 +38,7 @@ Checksum::get_length(ChecksumType checksum_type)
 std::string
 Checksum::compute_checksum(ChecksumType checksum_type, const std::string& data)
 {
-  return Glib::convert_return_gchar_ptr_to_ustring(
+  return Glib::convert_return_gchar_ptr_to_stdstring(
     g_compute_checksum_for_string(((GChecksumType)checksum_type), data.c_str(), data.size()));
 }
 
diff --git a/tests/giomm_memoryinputstream/main.cc b/tests/giomm_memoryinputstream/main.cc
index 2c35d1a1..ce1b54ec 100644
--- a/tests/giomm_memoryinputstream/main.cc
+++ b/tests/giomm_memoryinputstream/main.cc
@@ -27,7 +27,7 @@ destroy_func1(void* data)
 }
 
 void
-destroy_func2(void* data, const Glib::ustring& intro)
+destroy_func2(void* data, const std::string& intro)
 {
   char* cdata = static_cast<char*>(data);
   func2_output += intro + cdata;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]