mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Make profile_items use unique_ptr instead of raw pointers
This commit is contained in:
parent
9efa897d0d
commit
16bc7b48b5
2 changed files with 11 additions and 8 deletions
|
@ -234,20 +234,20 @@ void parser_t::forbid_function(const wcstring &function) { forbidden_function.pu
|
|||
void parser_t::allow_function() { forbidden_function.pop_back(); }
|
||||
|
||||
/// Print profiling information to the specified stream.
|
||||
static void print_profile(const std::vector<profile_item_t *> &items, FILE *out) {
|
||||
static void print_profile(const std::vector<std::unique_ptr<profile_item_t>> &items, FILE *out) {
|
||||
for (size_t pos = 0; pos < items.size(); pos++) {
|
||||
const profile_item_t *me, *prev;
|
||||
size_t i;
|
||||
int my_time;
|
||||
|
||||
me = items.at(pos);
|
||||
me = items.at(pos).get();
|
||||
if (me->skipped) {
|
||||
continue;
|
||||
}
|
||||
|
||||
my_time = me->parse + me->exec;
|
||||
for (i = pos + 1; i < items.size(); i++) {
|
||||
prev = items.at(i);
|
||||
prev = items.at(i).get();
|
||||
if (prev->skipped) {
|
||||
continue;
|
||||
}
|
||||
|
@ -569,10 +569,10 @@ job_t *parser_t::job_get_from_pid(int pid) {
|
|||
}
|
||||
|
||||
profile_item_t *parser_t::create_profile_item() {
|
||||
profile_item_t *result = NULL;
|
||||
profile_item_t *result = nullptr;
|
||||
if (g_profiling_active) {
|
||||
result = new profile_item_t();
|
||||
profile_items.push_back(result);
|
||||
profile_items.emplace_back(new profile_item_t());
|
||||
result = profile_items.back().get();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -196,8 +196,11 @@ class parser_t {
|
|||
wcstring block_stack_description() const;
|
||||
#endif
|
||||
|
||||
/// List of profile items, allocated with new.
|
||||
std::vector<profile_item_t *> profile_items;
|
||||
/// List of profile items
|
||||
/// These are pointers because we return pointers to them to callers,
|
||||
/// who may hold them across blocks (which would cause reallocations internal
|
||||
/// to profile_items)
|
||||
std::vector<std::unique_ptr<profile_item_t>> profile_items;
|
||||
|
||||
// No copying allowed.
|
||||
parser_t(const parser_t &);
|
||||
|
|
Loading…
Reference in a new issue