Changeset - r23531:603769aaf687
[Not reviewed]
master
0 8 0
Henry Wilson - 6 years ago 2018-09-25 21:01:05
m3henry@googlemail.com
Codechange: Replaced SmallVector::Erase() with std::vector::erase()
8 files changed with 24 insertions and 37 deletions:
0 comments (0 inline, 0 general)
src/core/smallmap_type.hpp
Show inline comments
 
@@ -112,28 +112,28 @@ struct SmallMap : SmallVector<SmallPair<
 
	 * @param pair pair to remove
 
	 * @note it has to be pointer to pair in this map. It is overwritten by the last item.
 
	 */
 
	inline void Erase(Pair *pair)
 
	{
 
		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);
 
	}
 

	
 
	/**
 
	 * Removes given key from this map
 
	 * @param key key to remove
 
	 * @return true iff the key was found
 
	 * @note last item is moved to its place, so don't increase your iterator if true is returned!
 
	 */
 
	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<Pair, S>::Erase(pair);
 
		std::vector<Pair>::erase(pair);
 
		return true;
 
	}
 

	
 
	/**
 
	 * Adds new item to this map.
 
	 * @param key key
src/core/smallvec_type.hpp
Show inline comments
 
@@ -101,24 +101,12 @@ public:
 
	{
 
		auto const it = std::find(std::vector<T>::begin(), std::vector<T>::end(), item);
 
		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.
 
	 * The '!=' operator of T is used for comparison.
 
	 * @param item Item to test for
 
	 * @return true iff the item is was already present
 
	 */
 
	inline bool Include(const T &item)
src/network/core/tcp_connect.cpp
Show inline comments
 
@@ -63,28 +63,28 @@ void TCPConnecter::Connect()
 
 * have connected or aborted and call the appropriate callback
 
 * for that. It's done this way to ease on the locking that
 
 * would otherwise be needed everywhere.
 
 */
 
/* 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;
 
		}
 
		iter++;
 
	}
src/network/core/tcp_http.cpp
Show inline comments
 
@@ -308,23 +308,23 @@ int NetworkHTTPSocketHandler::Receive()
 
	}
 

	
 
	tv.tv_sec = tv.tv_usec = 0; // don't block at all.
 
	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)) {
 
			int ret = cur->Receive();
 
			/* First send the failure. */
 
			if (ret < 0) cur->callback->OnFailure();
 
			if (ret <= 0) {
 
				/* Then... the connection can be closed */
 
				cur->CloseConnection();
 
				_http_connections.Erase(iter);
 
				iter = _http_connections.erase(iter);
 
				delete cur;
 
				continue;
 
			}
 
		}
 
		iter++;
 
	}
src/newgrf_debug_gui.cpp
Show inline comments
 
@@ -983,13 +983,13 @@ struct SpriteAlignerWindow : Window {
 
				MarkWholeScreenDirty();
 
				break;
 
			}
 

	
 
			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;
 
		}
 
	}
 

	
 
	void OnQueryTextFinished(char *str) override
src/sortlist_type.h
Show inline comments
 
@@ -334,19 +334,18 @@ public:
 
	bool Filter(FilterFunction *decide, F filter_data)
 
	{
 
		/* Do not filter if the filter bit is not set */
 
		if (!(this->flags & VL_FILTER)) return false;
 

	
 
		bool changed = false;
 
		for (uint iter = 0; iter < std::vector<T>::size();) {
 
			T *item = &std::vector<T>::operator[](iter);
 
			if (!decide(item, filter_data)) {
 
				this->Erase(item);
 
		for (auto it = std::vector<T>::begin(); it != std::vector<T>::end(); /* Nothing */) {
 
			if (!decide(&*it, filter_data)) {
 
				it = std::vector<T>::erase(it);
 
				changed = true;
 
			} else {
 
				iter++;
 
				it++;
 
			}
 
		}
 

	
 
		return changed;
 
	}
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -3538,14 +3538,14 @@ void DeleteStaleLinks(Station *from)
 
							}
 
						}
 
						if (!found_to || !found_from) continue;
 
						*(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.
 
						if (edge.LastUpdate() == _date) {
 
							updated = true;
 
							break;
 
@@ -3553,16 +3553,16 @@ void DeleteStaleLinks(Station *from)
 

	
 
						Vehicle *next_shared = v->NextShared();
 
						if (next_shared) {
 
							*iter = next_shared;
 
							++iter;
 
						} else {
 
							vehicles.Erase(iter);
 
						}
 

	
 
						if (iter == vehicles.End()) iter = vehicles.Begin();
 
							iter = vehicles.erase(iter);
 
						}
 

	
 
						if (iter == vehicles.end()) iter = vehicles.begin();
 
					}
 
				}
 

	
 
				if (!updated) {
 
					/* If it's still considered dead remove it. */
 
					node.RemoveEdge(to->goods[c].node);
src/station_gui.cpp
Show inline comments
 
@@ -2130,16 +2130,16 @@ template <class T>
 
static bool AddNearbyStation(TileIndex tile, void *user_data)
 
{
 
	TileArea *ctx = (TileArea *)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--;
 
		}
 
	}
 

	
 
	/* Check if own station and if we stay within station spread */
 
	if (!IsTileType(tile, MP_STATION)) return false;
0 comments (0 inline, 0 general)