mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use std::reverse instead of custom implementation. (#10918)
parent
a2c0e6aa18
commit
8a2d550904
|
@ -65,37 +65,4 @@ static inline int MemCmpT(const T *ptr1, const T *ptr2, size_t num = 1)
|
||||||
return memcmp(ptr1, ptr2, num * sizeof(T));
|
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 */
|
#endif /* MEM_FUNC_HPP */
|
||||||
|
|
|
@ -234,7 +234,7 @@ public:
|
||||||
{
|
{
|
||||||
this->flags ^= VL_DESC;
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue