enum ctf_msg_iter_medium_status status;
/* If we have gone through all index entries, we are done. */
- if (data->next_index_entry_index >= data->ds_file_group->index->entries->len) {
+ if (data->next_index_entry_index >= data->ds_file_group->index->entries.size()) {
status = CTF_MSG_ITER_MEDIUM_STATUS_EOF;
goto end;
}
* Otherwise, look up the next index entry / packet and prepare it
* for reading.
*/
- index_entry = (struct ctf_fs_ds_index_entry *) g_ptr_array_index(
- data->ds_file_group->index->entries, data->next_index_entry_index);
+ index_entry = data->ds_file_group->index->entries[data->next_index_entry_index].get();
status = ctf_fs_ds_group_medops_set_file(data, index_entry);
if (status != CTF_MSG_ITER_MEDIUM_STATUS_OK) {
BT_ASSERT(self_msg_iter);
BT_ASSERT(ds_file_group);
BT_ASSERT(ds_file_group->index);
- BT_ASSERT(ds_file_group->index->entries->len > 0);
+ BT_ASSERT(!ds_file_group->index->entries.empty());
ctf_fs_ds_group_medops_data *data = new ctf_fs_ds_group_medops_data {logCfg};
data->ds_file_group = ds_file_group;
.borrow_stream = medop_group_borrow_stream,
};
-static void ctf_fs_ds_index_entry_destroy(ctf_fs_ds_index_entry *entry)
-{
- delete entry;
-}
-
static ctf_fs_ds_index_entry::UP ctf_fs_ds_index_entry_create(const bt2_common::DataLen offset,
const bt2_common::DataLen packetSize)
{
prev_index_entry = index_entry.get();
- /* Give ownership of `index_entry` to `index->entries`. */
- g_ptr_array_add(index->entries, index_entry.release());
+ index->entries.emplace_back(std::move(index_entry));
}
/* Validate that the index addresses the complete stream. */
goto error;
}
- g_ptr_array_add(index->entries, index_entry.release());
+ index->entries.emplace_back(std::move(index_entry));
currentPacketOffset += currentPacketSize;
BT_CLOGD("Seeking to next packet: current-packet-offset-bytes=%llu, "
BT_HIDDEN
ctf_fs_ds_index::UP ctf_fs_ds_index_create(const bt2_common::LogCfg& logCfg)
{
- ctf_fs_ds_index::UP index {new ctf_fs_ds_index};
-
- index->entries = g_ptr_array_new_with_free_func((GDestroyNotify) ctf_fs_ds_index_entry_destroy);
- if (!index->entries) {
- BT_CLOGE("Failed to allocate index entries.");
- goto error;
- }
-
- goto end;
-
-error:
- index.reset();
-
-end:
- return index;
+ return ctf_fs_ds_index::UP {new ctf_fs_ds_index};
}
BT_HIDDEN
return;
}
- if (index->entries) {
- g_ptr_array_free(index->entries, TRUE);
- }
-
delete index;
}
return ret;
}
-/* Replace by g_ptr_array_insert when we depend on glib >= 2.40. */
-static void array_insert(GPtrArray *array, gpointer element, size_t pos)
-{
- size_t original_array_len = array->len;
-
- /* Allocate an unused element at the end of the array. */
- g_ptr_array_add(array, NULL);
-
- /* If we are not inserting at the end, move the elements by one. */
- if (pos < original_array_len) {
- memmove(&(array->pdata[pos + 1]), &(array->pdata[pos]),
- (original_array_len - pos) * sizeof(gpointer));
- }
-
- /* Insert the value. */
- array->pdata[pos] = element;
-}
-
/*
* Insert ds_file_info in ds_file_group's list of ds_file_infos at the right
* place to keep it sorted.
*/
static void ds_index_insert_ds_index_entry_sorted(struct ctf_fs_ds_index *index,
- struct ctf_fs_ds_index_entry *entry)
+ ctf_fs_ds_index_entry::UP entry)
{
- guint i;
- struct ctf_fs_ds_index_entry *other_entry = NULL;
-
/* Find the spot where to insert this index entry. */
- for (i = 0; i < index->entries->len; i++) {
- other_entry = (struct ctf_fs_ds_index_entry *) g_ptr_array_index(index->entries, i);
-
- if (entry->timestamp_begin_ns <= other_entry->timestamp_begin_ns) {
+ auto otherEntry = index->entries.begin();
+ for (; otherEntry != index->entries.end(); ++otherEntry) {
+ if (entry->timestamp_begin_ns <= (*otherEntry)->timestamp_begin_ns) {
break;
}
}
* snapshots of the same trace. We then want the index to contain
* a reference to only one copy of that packet.
*/
- if (i == index->entries->len || !ds_index_entries_equal(entry, other_entry)) {
- array_insert(index->entries, entry, i);
- } else {
- delete entry;
+ if (otherEntry == index->entries.end() ||
+ !ds_index_entries_equal(entry.get(), otherEntry->get())) {
+ index->entries.insert(otherEntry, std::move(entry));
}
}
static void merge_ctf_fs_ds_indexes(struct ctf_fs_ds_index *dest, ctf_fs_ds_index::UP src)
{
- guint i;
-
- for (i = 0; i < src->entries->len; i++) {
- struct ctf_fs_ds_index_entry *entry =
- (struct ctf_fs_ds_index_entry *) g_ptr_array_index(src->entries, i);
-
- /*
- * Ownership of the ctf_fs_ds_index_entry is transferred to
- * ds_index_insert_ds_index_entry_sorted.
- */
- g_ptr_array_index(src->entries, i) = NULL;
- ds_index_insert_ds_index_entry_sorted(dest, entry);
+ for (ctf_fs_ds_index_entry::UP& entry : src->entries) {
+ ds_index_insert_ds_index_entry_sorted(dest, std::move(entry));
}
}
const bt2_common::LogCfg& logCfg = trace->logCfg;
for (ctf_fs_ds_file_group::UP& ds_file_group : trace->ds_file_groups) {
- guint entry_i;
struct ctf_clock_class *default_cc;
- struct ctf_fs_ds_index_entry *last_entry;
struct ctf_fs_ds_index *index;
BT_ASSERT(ds_file_group);
index = ds_file_group->index.get();
BT_ASSERT(index);
- BT_ASSERT(index->entries);
- BT_ASSERT(index->entries->len > 0);
+ BT_ASSERT(!index->entries.empty());
/*
* Iterate over all entries but the last one. The last one is
* fixed differently after.
*/
- for (entry_i = 0; entry_i < index->entries->len - 1; entry_i++) {
- struct ctf_fs_ds_index_entry *curr_entry, *next_entry;
-
- curr_entry = (ctf_fs_ds_index_entry *) g_ptr_array_index(index->entries, entry_i);
- next_entry = (ctf_fs_ds_index_entry *) g_ptr_array_index(index->entries, entry_i + 1);
+ for (size_t entry_i = 0; entry_i < index->entries.size() - 1; ++entry_i) {
+ ctf_fs_ds_index_entry *curr_entry = index->entries[entry_i].get();
+ ctf_fs_ds_index_entry *next_entry = index->entries[entry_i + 1].get();
/*
* 1. Set the current index entry `end` timestamp to
* 2. Fix the last entry by decoding the last event of the last
* packet.
*/
- last_entry =
- (ctf_fs_ds_index_entry *) g_ptr_array_index(index->entries, index->entries->len - 1);
+ ctf_fs_ds_index_entry *last_entry = index->entries.back().get();
BT_ASSERT(last_entry);
BT_ASSERT(ds_file_group->sc->default_clock_class);
const bt2_common::LogCfg& logCfg = trace->logCfg;
for (ctf_fs_ds_file_group::UP& ds_file_group : trace->ds_file_groups) {
- guint entry_i;
struct ctf_clock_class *default_cc;
struct ctf_fs_ds_index *index = ds_file_group->index.get();
BT_ASSERT(index);
- BT_ASSERT(index->entries);
- BT_ASSERT(index->entries->len > 0);
+ BT_ASSERT(!index->entries.empty());
BT_ASSERT(ds_file_group->sc->default_clock_class);
default_cc = ds_file_group->sc->default_clock_class;
* 1. Iterate over the index, starting from the second entry
* (index = 1).
*/
- for (entry_i = 1; entry_i < index->entries->len; entry_i++) {
- ctf_fs_ds_index_entry *prev_entry =
- (ctf_fs_ds_index_entry *) g_ptr_array_index(index->entries, entry_i - 1);
- ctf_fs_ds_index_entry *curr_entry =
- (ctf_fs_ds_index_entry *) g_ptr_array_index(index->entries, entry_i);
+ for (size_t entry_i = 1; entry_i < index->entries.size(); ++entry_i) {
+ ctf_fs_ds_index_entry *prev_entry = index->entries[entry_i - 1].get();
+ ctf_fs_ds_index_entry *curr_entry = index->entries[entry_i].get();
/*
* 2. Set the current entry `begin` timestamp to the
* timestamp of the first event of the current packet.
const bt2_common::LogCfg& logCfg = trace->logCfg;
for (ctf_fs_ds_file_group::UP& ds_file_group : trace->ds_file_groups) {
- guint entry_idx;
struct ctf_clock_class *default_cc;
struct ctf_fs_ds_index *index;
default_cc = ds_file_group->sc->default_clock_class;
BT_ASSERT(index);
- BT_ASSERT(index->entries);
- BT_ASSERT(index->entries->len > 0);
+ BT_ASSERT(!index->entries.empty());
- ctf_fs_ds_index_entry *last_entry =
- (ctf_fs_ds_index_entry *) g_ptr_array_index(index->entries, index->entries->len - 1);
+ ctf_fs_ds_index_entry *last_entry = index->entries.back().get();
BT_ASSERT(last_entry);
/* 1. Fix the last entry first. */
}
/* Iterate over all entries but the last one. */
- for (entry_idx = 0; entry_idx < index->entries->len - 1; entry_idx++) {
- ctf_fs_ds_index_entry *curr_entry =
- (ctf_fs_ds_index_entry *) g_ptr_array_index(index->entries, entry_idx);
- ctf_fs_ds_index_entry *next_entry =
- (ctf_fs_ds_index_entry *) g_ptr_array_index(index->entries, entry_idx + 1);
+ for (size_t entry_idx = 0; entry_idx < index->entries.size() - 1; ++entry_idx) {
+ ctf_fs_ds_index_entry *curr_entry = index->entries[entry_idx].get();
+ ctf_fs_ds_index_entry *next_entry = index->entries[entry_idx + 1].get();
if (curr_entry->timestamp_end == 0 && curr_entry->timestamp_begin != 0) {
/*