mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Replaced SmallVector::Contains() with std::find() pattern
parent
b1f5119d3a
commit
5795f66d2e
|
@ -1207,7 +1207,7 @@ struct BuildVehicleWindow : Window {
|
||||||
this->eng_list.Filter(this->cargo_filter[this->cargo_filter_criteria]);
|
this->eng_list.Filter(this->cargo_filter[this->cargo_filter_criteria]);
|
||||||
if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine
|
if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine
|
||||||
this->SelectEngine(INVALID_ENGINE);
|
this->SelectEngine(INVALID_ENGINE);
|
||||||
} else if (!this->eng_list.Contains(this->sel_engine)) { // previously selected engine didn't pass the filter, select the first engine of the list
|
} else if (std::find(this->eng_list.begin(), this->eng_list.end(), this->sel_engine) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list
|
||||||
this->SelectEngine(this->eng_list[0]);
|
this->SelectEngine(this->eng_list[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,17 +114,6 @@ public:
|
||||||
return it == std::vector<T>::end() ? -1 : it - std::vector<T>::begin();
|
return it == std::vector<T>::end() ? -1 : it - std::vector<T>::begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether a item is present in the vector.
|
|
||||||
* The '!=' operator of T is used for comparison.
|
|
||||||
* @param item Item to test for
|
|
||||||
* @return true iff the item is present
|
|
||||||
*/
|
|
||||||
inline bool Contains(const T &item) const
|
|
||||||
{
|
|
||||||
return std::find(std::vector<T>::begin(), std::vector<T>::end(), item) != std::vector<T>::end();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes given item from this vector
|
* Removes given item from this vector
|
||||||
* @param item item to remove
|
* @param item item to remove
|
||||||
|
@ -145,7 +134,7 @@ public:
|
||||||
*/
|
*/
|
||||||
inline bool Include(const T &item)
|
inline bool Include(const T &item)
|
||||||
{
|
{
|
||||||
bool is_member = this->Contains(item);
|
bool is_member = std::find(std::vector<T>::begin(), std::vector<T>::end(), item) != std::vector<T>::end();
|
||||||
if (!is_member) *this->Append() = item;
|
if (!is_member) *this->Append() = item;
|
||||||
return is_member;
|
return is_member;
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,7 +301,9 @@ void HotkeyList::Save(IniFile *ini) const
|
||||||
int HotkeyList::CheckMatch(uint16 keycode, bool global_only) const
|
int HotkeyList::CheckMatch(uint16 keycode, bool global_only) const
|
||||||
{
|
{
|
||||||
for (const Hotkey *list = this->items; list->name != NULL; ++list) {
|
for (const Hotkey *list = this->items; list->name != NULL; ++list) {
|
||||||
if (list->keycodes.Contains(keycode | WKC_GLOBAL_HOTKEY) || (!global_only && list->keycodes.Contains(keycode))) {
|
auto begin = list->keycodes.begin();
|
||||||
|
auto end = list->keycodes.end();
|
||||||
|
if (std::find(begin, end, keycode | WKC_GLOBAL_HOTKEY) != end || (!global_only && std::find(begin, end, keycode) != end)) {
|
||||||
return list->num;
|
return list->num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -794,10 +794,9 @@ void ClientNetworkContentSocketHandler::SendReceive()
|
||||||
void ClientNetworkContentSocketHandler::DownloadContentInfo(ContentID cid)
|
void ClientNetworkContentSocketHandler::DownloadContentInfo(ContentID cid)
|
||||||
{
|
{
|
||||||
/* When we tried to download it already, don't try again */
|
/* When we tried to download it already, don't try again */
|
||||||
if (this->requested.Contains(cid)) return;
|
if (std::find(this->requested.begin(), this->requested.end(), cid) != this->requested.end()) return;
|
||||||
|
|
||||||
*this->requested.Append() = cid;
|
this->requested.push_back(cid);
|
||||||
assert(this->requested.Contains(cid));
|
|
||||||
this->RequestContentList(1, &cid);
|
this->RequestContentList(1, &cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -304,7 +304,7 @@ RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels)
|
||||||
/* Test if any rail type defines the label as an alternate. */
|
/* Test if any rail type defines the label as an alternate. */
|
||||||
for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
|
for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
|
||||||
const RailtypeInfo *rti = GetRailTypeInfo(r);
|
const RailtypeInfo *rti = GetRailTypeInfo(r);
|
||||||
if (rti->alternate_labels.Contains(label)) return r;
|
if (std::find(rti->alternate_labels.begin(), rti->alternate_labels.end(), label) != rti->alternate_labels.end()) return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2150,7 +2150,7 @@ static bool AddNearbyStation(TileIndex tile, void *user_data)
|
||||||
if (!T::IsValidID(sid)) return false;
|
if (!T::IsValidID(sid)) return false;
|
||||||
|
|
||||||
T *st = T::Get(sid);
|
T *st = T::Get(sid);
|
||||||
if (st->owner != _local_company || _stations_nearby_list.Contains(sid)) return false;
|
if (st->owner != _local_company || std::find(_stations_nearby_list.begin(), _stations_nearby_list.end(), sid) != _stations_nearby_list.end()) return false;
|
||||||
|
|
||||||
if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST).Succeeded()) {
|
if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST).Succeeded()) {
|
||||||
*_stations_nearby_list.Append() = sid;
|
*_stations_nearby_list.Append() = sid;
|
||||||
|
|
|
@ -355,7 +355,7 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles,
|
||||||
/* Reset actual_subtype for every new vehicle */
|
/* Reset actual_subtype for every new vehicle */
|
||||||
if (!v->IsArticulatedPart()) actual_subtype = new_subtype;
|
if (!v->IsArticulatedPart()) actual_subtype = new_subtype;
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN && !vehicles_to_refit.Contains(v->index) && !only_this) continue;
|
if (v->type == VEH_TRAIN && std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), v->index) == vehicles_to_refit.end() && !only_this) continue;
|
||||||
|
|
||||||
const Engine *e = v->GetEngine();
|
const Engine *e = v->GetEngine();
|
||||||
if (!e->CanCarryCargo()) continue;
|
if (!e->CanCarryCargo()) continue;
|
||||||
|
|
|
@ -267,7 +267,7 @@ byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_t
|
||||||
StringID subtype = GetCargoSubtypeText(v);
|
StringID subtype = GetCargoSubtypeText(v);
|
||||||
if (subtype == STR_EMPTY) break;
|
if (subtype == STR_EMPTY) break;
|
||||||
|
|
||||||
if (!subtypes.Contains(subtype)) continue;
|
if (std::find(subtypes.begin(), subtypes.end(), subtype) == subtypes.end()) continue;
|
||||||
|
|
||||||
/* We found something matching. */
|
/* We found something matching. */
|
||||||
ret_refit_cyc = refit_cyc;
|
ret_refit_cyc = refit_cyc;
|
||||||
|
@ -414,7 +414,7 @@ struct RefitWindow : public Window {
|
||||||
GetVehicleSet(vehicles_to_refit, Vehicle::Get(this->selected_vehicle), this->num_vehicles);
|
GetVehicleSet(vehicles_to_refit, Vehicle::Get(this->selected_vehicle), this->num_vehicles);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (v->type == VEH_TRAIN && !vehicles_to_refit.Contains(v->index)) continue;
|
if (v->type == VEH_TRAIN && std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), v->index) == vehicles_to_refit.end()) continue;
|
||||||
const Engine *e = v->GetEngine();
|
const Engine *e = v->GetEngine();
|
||||||
CargoTypes cmask = e->info.refit_mask;
|
CargoTypes cmask = e->info.refit_mask;
|
||||||
byte callback_mask = e->info.callback_mask;
|
byte callback_mask = e->info.callback_mask;
|
||||||
|
@ -747,14 +747,15 @@ struct RefitWindow : public Window {
|
||||||
|
|
||||||
for (Train *u = Train::From(v); u != NULL; u = u->Next()) {
|
for (Train *u = Train::From(v); u != NULL; u = u->Next()) {
|
||||||
/* Start checking. */
|
/* Start checking. */
|
||||||
if (vehicles_to_refit.Contains(u->index) && left == INT32_MIN) {
|
const bool contained = std::find(vehicles_to_refit.begin(), vehicles_to_refit.end(), u->index) != vehicles_to_refit.end();
|
||||||
|
if (contained && left == INT32_MIN) {
|
||||||
left = x - this->hscroll->GetPosition() + r.left + this->vehicle_margin;
|
left = x - this->hscroll->GetPosition() + r.left + this->vehicle_margin;
|
||||||
width = 0;
|
width = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw a selection. */
|
/* Draw a selection. */
|
||||||
if ((!vehicles_to_refit.Contains(u->index) || u->Next() == NULL) && left != INT32_MIN) {
|
if ((!contained || u->Next() == NULL) && left != INT32_MIN) {
|
||||||
if (u->Next() == NULL && vehicles_to_refit.Contains(u->index)) {
|
if (u->Next() == NULL && contained) {
|
||||||
int current_width = u->GetDisplayImageWidth();
|
int current_width = u->GetDisplayImageWidth();
|
||||||
width += current_width;
|
width += current_width;
|
||||||
x += current_width;
|
x += current_width;
|
||||||
|
|
Loading…
Reference in New Issue