mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Replaced SmallVector::Erase() with std::vector::erase()
parent
097328c3d7
commit
ca2f33c6d0
|
@ -115,7 +115,8 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
|
||||||
inline void Erase(Pair *pair)
|
inline void Erase(Pair *pair)
|
||||||
{
|
{
|
||||||
assert(pair >= this->Begin() && pair < this->End());
|
assert(pair >= this->Begin() && pair < this->End());
|
||||||
SmallVector<Pair, S>::Erase(pair);
|
auto distance = pair - std::vector<Pair>::data();
|
||||||
|
std::vector<Pair>::erase(std::vector<Pair>::begin() + distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,11 +127,10 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
|
||||||
*/
|
*/
|
||||||
inline bool Erase(const T &key)
|
inline bool Erase(const T &key)
|
||||||
{
|
{
|
||||||
Pair *pair = this->Find(key);
|
auto pair = std::find(this->begin(), this->end(), key);
|
||||||
if (pair == this->End())
|
if (pair == this->end()) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
SmallVector<Pair, S>::Erase(pair);
|
std::vector<Pair>::erase(pair);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,18 +103,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes given item from this vector
|
|
||||||
* @param item item to remove
|
|
||||||
* @note it has to be pointer to item in this map. It is overwritten by the last item.
|
|
||||||
*/
|
|
||||||
inline void Erase(T *item)
|
|
||||||
{
|
|
||||||
assert(item >= this->Begin() && item < this->End());
|
|
||||||
*item = std::vector<T>::back();
|
|
||||||
std::vector<T>::pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether a item is present in the vector, and appends it to the end if not.
|
* Tests whether a item is present in the vector, and appends it to the end if not.
|
||||||
* The '!=' operator of T is used for comparison.
|
* The '!=' operator of T is used for comparison.
|
||||||
|
|
|
@ -66,22 +66,22 @@ void TCPConnecter::Connect()
|
||||||
*/
|
*/
|
||||||
/* static */ void TCPConnecter::CheckCallbacks()
|
/* static */ void TCPConnecter::CheckCallbacks()
|
||||||
{
|
{
|
||||||
for (TCPConnecter **iter = _tcp_connecters.Begin(); iter < _tcp_connecters.End(); /* nothing */) {
|
for (auto iter = _tcp_connecters.begin(); iter < _tcp_connecters.end(); /* nothing */) {
|
||||||
TCPConnecter *cur = *iter;
|
TCPConnecter *cur = *iter;
|
||||||
if ((cur->connected || cur->aborted) && cur->killed) {
|
if ((cur->connected || cur->aborted) && cur->killed) {
|
||||||
_tcp_connecters.Erase(iter);
|
iter = _tcp_connecters.erase(iter);
|
||||||
if (cur->sock != INVALID_SOCKET) closesocket(cur->sock);
|
if (cur->sock != INVALID_SOCKET) closesocket(cur->sock);
|
||||||
delete cur;
|
delete cur;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cur->connected) {
|
if (cur->connected) {
|
||||||
_tcp_connecters.Erase(iter);
|
iter = _tcp_connecters.erase(iter);
|
||||||
cur->OnConnect(cur->sock);
|
cur->OnConnect(cur->sock);
|
||||||
delete cur;
|
delete cur;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cur->aborted) {
|
if (cur->aborted) {
|
||||||
_tcp_connecters.Erase(iter);
|
iter = _tcp_connecters.erase(iter);
|
||||||
cur->OnFailure();
|
cur->OnFailure();
|
||||||
delete cur;
|
delete cur;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -311,7 +311,7 @@ int NetworkHTTPSocketHandler::Receive()
|
||||||
int n = select(FD_SETSIZE, &read_fd, NULL, NULL, &tv);
|
int n = select(FD_SETSIZE, &read_fd, NULL, NULL, &tv);
|
||||||
if (n == -1) return;
|
if (n == -1) return;
|
||||||
|
|
||||||
for (NetworkHTTPSocketHandler **iter = _http_connections.Begin(); iter < _http_connections.End(); /* nothing */) {
|
for (auto iter = _http_connections.begin(); iter < _http_connections.end(); /* nothing */) {
|
||||||
NetworkHTTPSocketHandler *cur = *iter;
|
NetworkHTTPSocketHandler *cur = *iter;
|
||||||
|
|
||||||
if (FD_ISSET(cur->sock, &read_fd)) {
|
if (FD_ISSET(cur->sock, &read_fd)) {
|
||||||
|
@ -321,7 +321,7 @@ int NetworkHTTPSocketHandler::Receive()
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
/* Then... the connection can be closed */
|
/* Then... the connection can be closed */
|
||||||
cur->CloseConnection();
|
cur->CloseConnection();
|
||||||
_http_connections.Erase(iter);
|
iter = _http_connections.erase(iter);
|
||||||
delete cur;
|
delete cur;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -986,7 +986,7 @@ struct SpriteAlignerWindow : Window {
|
||||||
|
|
||||||
case WID_SA_RESET_REL:
|
case WID_SA_RESET_REL:
|
||||||
/* Reset the starting offsets for the current sprite. */
|
/* Reset the starting offsets for the current sprite. */
|
||||||
this->offs_start_map.Erase(this->current_sprite);
|
this->offs_start_map.erase(this->offs_start_map.begin() + this->current_sprite);
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,13 +337,12 @@ public:
|
||||||
if (!(this->flags & VL_FILTER)) return false;
|
if (!(this->flags & VL_FILTER)) return false;
|
||||||
|
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
for (uint iter = 0; iter < std::vector<T>::size();) {
|
for (auto it = std::vector<T>::begin(); it != std::vector<T>::end(); /* Nothing */) {
|
||||||
T *item = &std::vector<T>::operator[](iter);
|
if (!decide(&*it, filter_data)) {
|
||||||
if (!decide(item, filter_data)) {
|
it = std::vector<T>::erase(it);
|
||||||
this->Erase(item);
|
|
||||||
changed = true;
|
changed = true;
|
||||||
} else {
|
} else {
|
||||||
iter++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3541,8 +3541,8 @@ void DeleteStaleLinks(Station *from)
|
||||||
*(vehicles.Append()) = l->GetFirstSharedVehicle();
|
*(vehicles.Append()) = l->GetFirstSharedVehicle();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vehicle **iter = vehicles.Begin();
|
auto iter = vehicles.begin();
|
||||||
while (iter != vehicles.End()) {
|
while (iter != vehicles.end()) {
|
||||||
Vehicle *v = *iter;
|
Vehicle *v = *iter;
|
||||||
|
|
||||||
LinkRefresher::Run(v, false); // Don't allow merging. Otherwise lg might get deleted.
|
LinkRefresher::Run(v, false); // Don't allow merging. Otherwise lg might get deleted.
|
||||||
|
@ -3556,10 +3556,10 @@ void DeleteStaleLinks(Station *from)
|
||||||
*iter = next_shared;
|
*iter = next_shared;
|
||||||
++iter;
|
++iter;
|
||||||
} else {
|
} else {
|
||||||
vehicles.Erase(iter);
|
iter = vehicles.erase(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iter == vehicles.End()) iter = vehicles.Begin();
|
if (iter == vehicles.end()) iter = vehicles.begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2133,10 +2133,10 @@ static bool AddNearbyStation(TileIndex tile, void *user_data)
|
||||||
|
|
||||||
/* First check if there were deleted stations here */
|
/* First check if there were deleted stations here */
|
||||||
for (uint i = 0; i < _deleted_stations_nearby.size(); i++) {
|
for (uint i = 0; i < _deleted_stations_nearby.size(); i++) {
|
||||||
TileAndStation *ts = _deleted_stations_nearby.data() + i;
|
auto ts = _deleted_stations_nearby.begin() + i;
|
||||||
if (ts->tile == tile) {
|
if (ts->tile == tile) {
|
||||||
*_stations_nearby_list.Append() = _deleted_stations_nearby[i].station;
|
*_stations_nearby_list.Append() = _deleted_stations_nearby[i].station;
|
||||||
_deleted_stations_nearby.Erase(ts);
|
_deleted_stations_nearby.erase(ts);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue