From 4d19995424130fc928c85e7c6f10b0c3d271e3af Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 4 Dec 2023 20:06:58 +0000 Subject: [PATCH] src.ctf.fs: make ctf_fs_ds_file_info::path an std::string Change-Id: If7e5c09024451b1c344a0446a75703929aff480e Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8248 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12286 --- src/plugins/ctf/fs-src/data-stream-file.cpp | 17 +++-------------- src/plugins/ctf/fs-src/data-stream-file.hpp | 4 ++-- src/plugins/ctf/fs-src/fs.cpp | 6 +++--- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/plugins/ctf/fs-src/data-stream-file.cpp b/src/plugins/ctf/fs-src/data-stream-file.cpp index 9f50f7ce..c1fcad27 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.cpp +++ b/src/plugins/ctf/fs-src/data-stream-file.cpp @@ -613,7 +613,7 @@ static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file * } /* Set path to stream file. */ - index_entry->path = file_info->path->str; + index_entry->path = file_info->path.c_str(); index_entry->timestamp_begin = be64toh(file_index->timestamp_begin); index_entry->timestamp_end = be64toh(file_index->timestamp_end); @@ -795,7 +795,7 @@ static struct ctf_fs_ds_index *build_index_from_stream_file(struct ctf_fs_ds_fil } /* Set path to stream file. */ - index_entry->path = file_info->path->str; + index_entry->path = file_info->path.c_str(); ret = init_index_entry(index_entry, ds_file, &props); if (ret) { @@ -932,26 +932,15 @@ void ctf_fs_ds_file_info_destroy(struct ctf_fs_ds_file_info *ds_file_info) return; } - if (ds_file_info->path) { - g_string_free(ds_file_info->path, TRUE); - } - delete ds_file_info; } struct ctf_fs_ds_file_info *ctf_fs_ds_file_info_create(const char *path, int64_t begin_ns) { ctf_fs_ds_file_info *ds_file_info = new ctf_fs_ds_file_info; - ds_file_info->path = g_string_new(path); - if (!ds_file_info->path) { - ctf_fs_ds_file_info_destroy(ds_file_info); - ds_file_info = NULL; - goto end; - } + ds_file_info->path = path; ds_file_info->begin_ns = begin_ns; - -end: return ds_file_info; } diff --git a/src/plugins/ctf/fs-src/data-stream-file.hpp b/src/plugins/ctf/fs-src/data-stream-file.hpp index 8f770705..6b5c3db7 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.hpp +++ b/src/plugins/ctf/fs-src/data-stream-file.hpp @@ -8,6 +8,7 @@ #define CTF_FS_DS_FILE_H #include +#include #include #include @@ -21,8 +22,7 @@ struct ctf_fs_ds_file_info { - /* Owned by this. */ - GString *path = nullptr; + std::string path; /* Guaranteed to be set, as opposed to the index. */ int64_t begin_ns = 0; diff --git a/src/plugins/ctf/fs-src/fs.cpp b/src/plugins/ctf/fs-src/fs.cpp index d49e9879..40ef7439 100644 --- a/src/plugins/ctf/fs-src/fs.cpp +++ b/src/plugins/ctf/fs-src/fs.cpp @@ -363,7 +363,7 @@ bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group) BT_ASSERT(ds_file_group->ds_file_infos->len == 1); struct ctf_fs_ds_file_info *ds_file_info = (struct ctf_fs_ds_file_info *) g_ptr_array_index(ds_file_group->ds_file_infos, 0); - g_string_append_printf(name, " | %s", ds_file_info->path->str); + g_string_append_printf(name, " | %s", ds_file_info->path.c_str()); } return bt2c::GCharUP {g_string_free(name, FALSE)}; @@ -1724,7 +1724,7 @@ static bool compare_ds_file_groups_by_first_path(const ctf_fs_ds_file_group::UP& const ctf_fs_ds_file_info *first_ds_file_info_b = (const ctf_fs_ds_file_info *) ds_file_group_b->ds_file_infos->pdata[0]; - return strcmp(first_ds_file_info_a->path->str, first_ds_file_info_b->path->str) < 0; + return first_ds_file_info_a->path < first_ds_file_info_b->path; } static gint compare_strings(gconstpointer p_a, gconstpointer p_b) @@ -1884,7 +1884,7 @@ static GString *get_stream_instance_unique_name(struct ctf_fs_ds_file_group *ds_ */ BT_ASSERT(ds_file_group->ds_file_infos->len > 0); ds_file_info = (ctf_fs_ds_file_info *) g_ptr_array_index(ds_file_group->ds_file_infos, 0); - g_string_assign(name, ds_file_info->path->str); + g_string_assign(name, ds_file_info->path.c_str()); end: return name; -- 2.34.1