Changeset - r27484:8711a462cdc1
[Not reviewed]
master
0 2 0
PeterN - 12 months ago 2023-06-03 22:25:01
peter1138@openttd.org
Codechange: Use std::reverse instead of custom implementation. (#10918)
2 files changed with 1 insertions and 34 deletions:
0 comments (0 inline, 0 general)
src/core/mem_func.hpp
Show inline comments
 
@@ -65,37 +65,4 @@ static inline int MemCmpT(const T *ptr1,
 
	return memcmp(ptr1, ptr2, num * sizeof(T));
 
}
 

	
 
/**
 
 * Type safe memory reverse operation.
 
 *  Reverse a block of memory in steps given by the
 
 *  type of the pointers.
 
 *
 
 * @param ptr1 Start-pointer to the block of memory.
 
 * @param ptr2 End-pointer to the block of memory.
 
 */
 
template <typename T>
 
static inline void MemReverseT(T *ptr1, T *ptr2)
 
{
 
	assert(ptr1 != nullptr && ptr2 != nullptr);
 
	assert(ptr1 < ptr2);
 

	
 
	do {
 
		Swap(*ptr1, *ptr2);
 
	} while (++ptr1 < --ptr2);
 
}
 

	
 
/**
 
 * Type safe memory reverse operation (overloaded)
 
 *
 
 * @param ptr Pointer to the block of memory.
 
 * @param num The number of items we want to reverse.
 
 */
 
template <typename T>
 
static inline void MemReverseT(T *ptr, size_t num)
 
{
 
	assert(ptr != nullptr);
 

	
 
	MemReverseT(ptr, ptr + (num - 1));
 
}
 

	
 
#endif /* MEM_FUNC_HPP */
src/sortlist_type.h
Show inline comments
 
@@ -234,7 +234,7 @@ public:
 
	{
 
		this->flags ^= VL_DESC;
 

	
 
		if (this->IsSortable()) MemReverseT(std::vector<T>::data(), std::vector<T>::size());
 
		if (this->IsSortable()) std::reverse(std::vector<T>::begin(), std::vector<T>::end());
 
	}
 

	
 
	/**
0 comments (0 inline, 0 general)