mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
Dramatically improve performance when sorting vectors of PointerTo objects
This commit is contained in:
parent
24b8bd8b96
commit
8c0b0990a8
@ -163,6 +163,20 @@ PUBLISHED:
|
||||
};
|
||||
|
||||
|
||||
// The existence of these functions makes it possible to sort vectors
|
||||
// of PointerTo objects without incurring the cost of unnecessary
|
||||
// reference count changes. The performance difference is dramatic!
|
||||
template <class T>
|
||||
void swap(PointerTo<T> &one, PointerTo<T> &two) {
|
||||
one.swap(two);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void swap(ConstPointerTo<T> &one, ConstPointerTo<T> &two) {
|
||||
one.swap(two);
|
||||
}
|
||||
|
||||
|
||||
// Finally, we'll define a couple of handy abbreviations to save on
|
||||
// all that wasted typing time.
|
||||
|
||||
|
@ -105,3 +105,13 @@ operator != (const PointerToVoid &other) const {
|
||||
return _void_ptr != other._void_ptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PointerToVoid::swap
|
||||
// Access: Public
|
||||
// Description: Swaps the contents of this PointerTo with the other,
|
||||
// without touching the reference counts.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void PointerToVoid::
|
||||
swap(PointerToVoid &other) {
|
||||
std::swap(_void_ptr, other._void_ptr);
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "memoryBase.h"
|
||||
#include "atomicAdjust.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PointerToVoid
|
||||
// Description : This is the non-template part of the base class for
|
||||
@ -52,6 +54,8 @@ public:
|
||||
INLINE bool operator == (const PointerToVoid &other) const;
|
||||
INLINE bool operator != (const PointerToVoid &other) const;
|
||||
|
||||
INLINE void swap(PointerToVoid &other);
|
||||
|
||||
protected:
|
||||
// Within the PointerToVoid class, we only store a void pointer.
|
||||
// This is actually the (To *) pointer that is typecast to (void *)
|
||||
|
Loading…
x
Reference in New Issue
Block a user