]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Refactor away the last instance of from_owned_cstr
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 27 Jan 2020 20:57:17 +0000 (21:57 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 28 Jan 2020 19:49:14 +0000 (20:49 +0100)
src/ccache.cpp
src/legacy_util.cpp
src/legacy_util.hpp
unittest/test_legacy_util.cpp

index 937e0e03063d23ad91b3b5dc935157ba1f8b5291..6a268183fa6b9d7672c931d2c3736bd9a26131ba 100644 (file)
@@ -2665,7 +2665,7 @@ cc_process_args(ArgsInfo& args_info,
       continue;
     }
     if (str_startswith(argv[i], "-fprofile-dir=")) {
-      args_info.profile_dir = from_owned_cstr(x_strdup(argv[i] + 14));
+      args_info.profile_dir.assign(argv[i] + 14);
       args_add(common_args, argv[i]);
       continue;
     }
index 9ff9c835745ba3db9a5ccf29abab3ef575a59a75..d5020ca8ee4c1c2f29a7b586cd6b0db8eef96807 100644 (file)
@@ -1544,17 +1544,6 @@ time_seconds(void)
 #endif
 }
 
-std::string
-from_owned_cstr(char* str)
-{
-  std::string result;
-  if (str) {
-    result = str;
-    free(str);
-  }
-  return result;
-}
-
 std::string
 from_cstr(const char* str)
 {
index 37e909fbc2f6eb04a5202f19e533e7b72dfa803f..9b622ce91eb29d1c72f1313dc160cb301e9859c2 100644 (file)
@@ -81,8 +81,5 @@ char* subst_env_in_string(const char* str, char** errmsg);
 void set_cloexec_flag(int fd);
 double time_seconds();
 
-// Convert an owned char* string `str` to an std::string and free `str`.
-std::string from_owned_cstr(char* str);
-
 // Convert a char* string `str` to an std::string, if `str` is NULL return "".
 std::string from_cstr(const char* str);
index c79f475d2e2a428baa70a8e1724f3c5408e6cdfe..dad59f16bdda03d6140b145677e962c052b73a7d 100644 (file)
@@ -214,22 +214,4 @@ TEST(from_cstr)
   free(cstr1);
 }
 
-TEST(from_owned_cstr)
-{
-  char* cstr1 = x_strdup("foo");
-  char* cstr2 = x_strdup("bar");
-  char* cstr3 = nullptr;
-  char* cstr4 = x_strdup("");
-
-  std::string str1 = from_owned_cstr(cstr1);
-  std::string str2 = from_owned_cstr(cstr2);
-  std::string str3 = from_owned_cstr(cstr3);
-  std::string str4 = from_owned_cstr(cstr4);
-
-  CHECK(str1 == "foo");
-  CHECK(str2 == "bar");
-  CHECK(str3 == "");
-  CHECK(str4 == "");
-}
-
 TEST_SUITE_END