From f9781e8c38c272d6ae54eb71591f49f23873b390 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Mon, 27 Jan 2020 21:57:17 +0100 Subject: [PATCH] Refactor away the last instance of from_owned_cstr --- src/ccache.cpp | 2 +- src/legacy_util.cpp | 11 ----------- src/legacy_util.hpp | 3 --- unittest/test_legacy_util.cpp | 18 ------------------ 4 files changed, 1 insertion(+), 33 deletions(-) diff --git a/src/ccache.cpp b/src/ccache.cpp index 937e0e030..6a268183f 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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; } diff --git a/src/legacy_util.cpp b/src/legacy_util.cpp index 9ff9c8357..d5020ca8e 100644 --- a/src/legacy_util.cpp +++ b/src/legacy_util.cpp @@ -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) { diff --git a/src/legacy_util.hpp b/src/legacy_util.hpp index 37e909fbc..9b622ce91 100644 --- a/src/legacy_util.hpp +++ b/src/legacy_util.hpp @@ -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); diff --git a/unittest/test_legacy_util.cpp b/unittest/test_legacy_util.cpp index c79f475d2..dad59f16b 100644 --- a/unittest/test_legacy_util.cpp +++ b/unittest/test_legacy_util.cpp @@ -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 -- 2.47.2