mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use smart pointers for CargoDataEntry children container
Replace manual memory management used for the container holding leaves in the CargoDataEntry tree structure with std::unique_ptr.pull/12295/head
parent
a7625b8ae0
commit
b930c1e7b6
|
@ -1022,7 +1022,7 @@ private:
|
||||||
};
|
};
|
||||||
uint num_children; ///< the number of subentries belonging to this entry.
|
uint num_children; ///< the number of subentries belonging to this entry.
|
||||||
uint count; ///< sum of counts of all children or amount of cargo for this entry.
|
uint count; ///< sum of counts of all children or amount of cargo for this entry.
|
||||||
CargoDataSet *children; ///< the children of this entry.
|
std::unique_ptr<CargoDataSet> children; ///< the children of this entry.
|
||||||
};
|
};
|
||||||
|
|
||||||
CargoDataEntry::CargoDataEntry() :
|
CargoDataEntry::CargoDataEntry() :
|
||||||
|
@ -1030,7 +1030,7 @@ CargoDataEntry::CargoDataEntry() :
|
||||||
station(INVALID_STATION),
|
station(INVALID_STATION),
|
||||||
num_children(0),
|
num_children(0),
|
||||||
count(0),
|
count(0),
|
||||||
children(new CargoDataSet(CargoSorter(CargoSortType::CargoID)))
|
children(std::make_unique<CargoDataSet>(CargoSorter(CargoSortType::CargoID)))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CargoDataEntry::CargoDataEntry(CargoID cargo, uint count, CargoDataEntry *parent) :
|
CargoDataEntry::CargoDataEntry(CargoID cargo, uint count, CargoDataEntry *parent) :
|
||||||
|
@ -1038,7 +1038,7 @@ CargoDataEntry::CargoDataEntry(CargoID cargo, uint count, CargoDataEntry *parent
|
||||||
cargo(cargo),
|
cargo(cargo),
|
||||||
num_children(0),
|
num_children(0),
|
||||||
count(count),
|
count(count),
|
||||||
children(new CargoDataSet)
|
children(std::make_unique<CargoDataSet>())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CargoDataEntry::CargoDataEntry(StationID station, uint count, CargoDataEntry *parent) :
|
CargoDataEntry::CargoDataEntry(StationID station, uint count, CargoDataEntry *parent) :
|
||||||
|
@ -1046,7 +1046,7 @@ CargoDataEntry::CargoDataEntry(StationID station, uint count, CargoDataEntry *pa
|
||||||
station(station),
|
station(station),
|
||||||
num_children(0),
|
num_children(0),
|
||||||
count(count),
|
count(count),
|
||||||
children(new CargoDataSet)
|
children(std::make_unique<CargoDataSet>())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CargoDataEntry::CargoDataEntry(StationID station) :
|
CargoDataEntry::CargoDataEntry(StationID station) :
|
||||||
|
@ -1068,7 +1068,6 @@ CargoDataEntry::CargoDataEntry(CargoID cargo) :
|
||||||
CargoDataEntry::~CargoDataEntry()
|
CargoDataEntry::~CargoDataEntry()
|
||||||
{
|
{
|
||||||
this->Clear();
|
this->Clear();
|
||||||
delete this->children;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1146,9 +1145,7 @@ void CargoDataEntry::IncrementSize()
|
||||||
|
|
||||||
void CargoDataEntry::Resort(CargoSortType type, SortOrder order)
|
void CargoDataEntry::Resort(CargoSortType type, SortOrder order)
|
||||||
{
|
{
|
||||||
CargoDataSet *new_subs = new CargoDataSet(this->children->begin(), this->children->end(), CargoSorter(type, order));
|
this->children = std::make_unique<CargoDataSet>(this->children->begin(), this->children->end(), CargoSorter(type, order));
|
||||||
delete this->children;
|
|
||||||
this->children = new_subs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CargoDataEntry *CargoDataEntry::Retrieve(CargoDataSet::iterator i) const
|
CargoDataEntry *CargoDataEntry::Retrieve(CargoDataSet::iterator i) const
|
||||||
|
|
Loading…
Reference in New Issue