From ca2f33c6d025c0c45fb4bc472493290445312de5 Mon Sep 17 00:00:00 2001 From: Henry Wilson Date: Tue, 25 Sep 2018 22:01:05 +0100 Subject: Codechange: Replaced SmallVector::Erase() with std::vector::erase() --- src/core/smallmap_type.hpp | 10 +++++----- src/core/smallvec_type.hpp | 12 ------------ src/network/core/tcp_connect.cpp | 8 ++++---- src/network/core/tcp_http.cpp | 4 ++-- src/newgrf_debug_gui.cpp | 2 +- src/sortlist_type.h | 9 ++++----- src/station_cmd.cpp | 8 ++++---- src/station_gui.cpp | 4 ++-- 8 files changed, 22 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp index 44ace6b45..0bd9bd296 100644 --- a/src/core/smallmap_type.hpp +++ b/src/core/smallmap_type.hpp @@ -115,7 +115,8 @@ struct SmallMap : SmallVector, S> { inline void Erase(Pair *pair) { assert(pair >= this->Begin() && pair < this->End()); - SmallVector::Erase(pair); + auto distance = pair - std::vector::data(); + std::vector::erase(std::vector::begin() + distance); } /** @@ -126,11 +127,10 @@ struct SmallMap : SmallVector, S> { */ inline bool Erase(const T &key) { - Pair *pair = this->Find(key); - if (pair == this->End()) - return false; + auto pair = std::find(this->begin(), this->end(), key); + if (pair == this->end()) return false; - SmallVector::Erase(pair); + std::vector::erase(pair); return true; } diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp index 1ec336b73..b989d44c5 100644 --- a/src/core/smallvec_type.hpp +++ b/src/core/smallvec_type.hpp @@ -103,18 +103,6 @@ public: return it == std::vector::end() ? -1 : it - std::vector::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::back(); - std::vector::pop_back(); - } - /** * 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. diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp index 95f9662cd..470d97e68 100644 --- a/src/network/core/tcp_connect.cpp +++ b/src/network/core/tcp_connect.cpp @@ -66,22 +66,22 @@ void TCPConnecter::Connect() */ /* 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; if ((cur->connected || cur->aborted) && cur->killed) { - _tcp_connecters.Erase(iter); + iter = _tcp_connecters.erase(iter); if (cur->sock != INVALID_SOCKET) closesocket(cur->sock); delete cur; continue; } if (cur->connected) { - _tcp_connecters.Erase(iter); + iter = _tcp_connecters.erase(iter); cur->OnConnect(cur->sock); delete cur; continue; } if (cur->aborted) { - _tcp_connecters.Erase(iter); + iter = _tcp_connecters.erase(iter); cur->OnFailure(); delete cur; continue; diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp index d2ab0638c..2d3e89b4e 100644 --- a/src/network/core/tcp_http.cpp +++ b/src/network/core/tcp_http.cpp @@ -311,7 +311,7 @@ int NetworkHTTPSocketHandler::Receive() int n = select(FD_SETSIZE, &read_fd, NULL, NULL, &tv); 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; if (FD_ISSET(cur->sock, &read_fd)) { @@ -321,7 +321,7 @@ int NetworkHTTPSocketHandler::Receive() if (ret <= 0) { /* Then... the connection can be closed */ cur->CloseConnection(); - _http_connections.Erase(iter); + iter = _http_connections.erase(iter); delete cur; continue; } diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index ec1a91d7b..a08124357 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -986,7 +986,7 @@ struct SpriteAlignerWindow : Window { case WID_SA_RESET_REL: /* 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(); break; } diff --git a/src/sortlist_type.h b/src/sortlist_type.h index 74b6f37b3..23a558018 100644 --- a/src/sortlist_type.h +++ b/src/sortlist_type.h @@ -337,13 +337,12 @@ public: if (!(this->flags & VL_FILTER)) return false; bool changed = false; - for (uint iter = 0; iter < std::vector::size();) { - T *item = &std::vector::operator[](iter); - if (!decide(item, filter_data)) { - this->Erase(item); + for (auto it = std::vector::begin(); it != std::vector::end(); /* Nothing */) { + if (!decide(&*it, filter_data)) { + it = std::vector::erase(it); changed = true; } else { - iter++; + it++; } } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index f7e2a1824..2dee09fe8 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3541,8 +3541,8 @@ void DeleteStaleLinks(Station *from) *(vehicles.Append()) = l->GetFirstSharedVehicle(); } - Vehicle **iter = vehicles.Begin(); - while (iter != vehicles.End()) { + auto iter = vehicles.begin(); + while (iter != vehicles.end()) { Vehicle *v = *iter; 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; } else { - vehicles.Erase(iter); + iter = vehicles.erase(iter); } - if (iter == vehicles.End()) iter = vehicles.Begin(); + if (iter == vehicles.end()) iter = vehicles.begin(); } } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 157d571af..e1f5daa69 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -2133,10 +2133,10 @@ static bool AddNearbyStation(TileIndex tile, void *user_data) /* First check if there were deleted stations here */ 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) { *_stations_nearby_list.Append() = _deleted_stations_nearby[i].station; - _deleted_stations_nearby.Erase(ts); + _deleted_stations_nearby.erase(ts); i--; } } -- cgit v1.2.3-70-g09d2