swap optimization

This commit is contained in:
Aleksandar Fabijanic 2007-10-27 18:53:32 +00:00
parent 5eb03ba814
commit 9ea88d25dd
6 changed files with 205 additions and 11 deletions

View File

@ -206,9 +206,27 @@ inline void BLOB::compact()
}
inline void swap(BLOB& b1, BLOB& b2)
{
b1.swap(b2);
}
} } // namespace Poco::Data
namespace std
{
template<>
inline void swap<Poco::Data::BLOB>(Poco::Data::BLOB& b1,
Poco::Data::BLOB& b2)
/// Full template specalization of std:::swap for BLOB
{
b1.swap(b2);
}
}
//
// DynamicAnyHolderImpl<BLOB>
//

View File

@ -93,8 +93,9 @@ public:
void swap(Column& other)
/// Swaps the column with another one.
{
std::swap(_metaColumn, other._metaColumn);
std::swap(_pData, other._pData);
using std::swap;
swap(_metaColumn, other._metaColumn);
swap(_pData, other._pData);
}
Container& data()
@ -238,9 +239,10 @@ public:
void swap(Column& other)
/// Swaps the column with another one.
{
std::swap(_metaColumn, other._metaColumn);
std::swap(_pData, other._pData);
std::swap(_deque, other._deque);
using std::swap;
swap(_metaColumn, other._metaColumn);
swap(_pData, other._pData);
swap(_deque, other._deque);
}
Container& data()
@ -373,8 +375,9 @@ public:
void swap(Column& other)
/// Swaps the column with another one.
{
std::swap(_metaColumn, other._metaColumn);
std::swap(_pData, other._pData);
using std::swap;
swap(_metaColumn, other._metaColumn);
swap(_pData, other._pData);
}
List& data()
@ -482,6 +485,13 @@ private:
};
template <typename T, typename C>
inline void swap(Column<T,C>& c1, Column<T,C>& c2)
{
c1.swap(c2);
}
} } // namespace Poco::Data

View File

@ -330,7 +330,25 @@ inline SessionImpl* Session::impl()
}
inline void swap(Session& s1, Session& s2)
{
s1.swap(s2);
}
} } // namespace Poco::Data
namespace std
{
template<>
inline void swap<Poco::Data::Session>(Poco::Data::Session& s1,
Poco::Data::Session& s2)
/// Full template specalization of std:::swap for Session
{
s1.swap(s2);
}
}
#endif // Data_Session_INCLUDED

View File

@ -438,7 +438,25 @@ inline bool Statement::isAsync() const
}
inline void swap(Statement& s1, Statement& s2)
{
s1.swap(s2);
}
} } // namespace Poco::Data
namespace std
{
template<>
inline void swap<Poco::Data::Statement>(Poco::Data::Statement& s1,
Poco::Data::Statement& s2)
/// Full template specalization of std:::swap for Statement
{
s1.swap(s2);
}
}
#endif // Data_Statement_INCLUDED

View File

@ -87,10 +87,12 @@ Statement& Statement::operator = (const Statement& stmt)
void Statement::swap(Statement& other)
{
std::swap(_ptr, other._ptr);
std::swap(_async, other._async);
std::swap(_pAsyncExec, other._pAsyncExec);
std::swap(_pResult, other._pResult);
using std::swap;
swap(_ptr, other._ptr);
swap(_async, other._async);
swap(_pAsyncExec, other._pAsyncExec);
swap(_pResult, other._pResult);
}

View File

@ -196,6 +196,11 @@ void DataTest::testBLOB()
assert (blobNumStr.content() != blobChrStr.content());
assert (&blobNumStr.content() != &blobChrStr.content());
assert (blobNumStr == blobChrVec);
Poco::Data::swap(blobNumStr, blobChrVec);
assert (blobNumStr == blobChrVec);
std::swap(blobNumStr, blobChrVec);
assert (blobNumStr == blobChrVec);
}
@ -420,6 +425,47 @@ void DataTest::testColumnVector()
assert (c.rowCount() == 0);
assert (c1.rowCount() == 0);
assert (c2.rowCount() == 0);
std::vector<int>* pV1 = new std::vector<int>;
pV1->push_back(1);
pV1->push_back(2);
pV1->push_back(3);
pV1->push_back(4);
pV1->push_back(5);
std::vector<int>* pV2 = new std::vector<int>;
pV2->push_back(5);
pV2->push_back(4);
pV2->push_back(3);
pV2->push_back(2);
pV2->push_back(1);
Column<int, std::vector<int> > c3(mc, pV1);
Column<int, std::vector<int> > c4(mc, pV2);
Poco::Data::swap(c3, c4);
assert (c3[0] == 5);
assert (c3[1] == 4);
assert (c3[2] == 3);
assert (c3[3] == 2);
assert (c3[4] == 1);
assert (c4[0] == 1);
assert (c4[1] == 2);
assert (c4[2] == 3);
assert (c4[3] == 4);
assert (c4[4] == 5);
std::swap(c3, c4);
assert (c3[0] == 1);
assert (c3[1] == 2);
assert (c3[2] == 3);
assert (c3[3] == 4);
assert (c3[4] == 5);
assert (c4[0] == 5);
assert (c4[1] == 4);
assert (c4[2] == 3);
assert (c4[3] == 2);
assert (c4[4] == 1);
}
@ -558,6 +604,47 @@ void DataTest::testColumnDeque()
assert (c.rowCount() == 0);
assert (c1.rowCount() == 0);
assert (c2.rowCount() == 0);
ContainerType* pV1 = new ContainerType;
pV1->push_back(1);
pV1->push_back(2);
pV1->push_back(3);
pV1->push_back(4);
pV1->push_back(5);
ContainerType* pV2 = new ContainerType;
pV2->push_back(5);
pV2->push_back(4);
pV2->push_back(3);
pV2->push_back(2);
pV2->push_back(1);
Column<int> c3(mc, pV1);
Column<int> c4(mc, pV2);
Poco::Data::swap(c3, c4);
assert (c3[0] == 5);
assert (c3[1] == 4);
assert (c3[2] == 3);
assert (c3[3] == 2);
assert (c3[4] == 1);
assert (c4[0] == 1);
assert (c4[1] == 2);
assert (c4[2] == 3);
assert (c4[3] == 4);
assert (c4[4] == 5);
std::swap(c3, c4);
assert (c3[0] == 1);
assert (c3[1] == 2);
assert (c3[2] == 3);
assert (c3[3] == 4);
assert (c3[4] == 5);
assert (c4[0] == 5);
assert (c4[1] == 4);
assert (c4[2] == 3);
assert (c4[3] == 2);
assert (c4[4] == 1);
}
@ -632,6 +719,47 @@ void DataTest::testColumnList()
assert (c.rowCount() == 0);
assert (c1.rowCount() == 0);
assert (c2.rowCount() == 0);
ContainerType* pV1 = new ContainerType;
pV1->push_back(1);
pV1->push_back(2);
pV1->push_back(3);
pV1->push_back(4);
pV1->push_back(5);
ContainerType* pV2 = new ContainerType;
pV2->push_back(5);
pV2->push_back(4);
pV2->push_back(3);
pV2->push_back(2);
pV2->push_back(1);
Column<int, ContainerType> c3(mc, pV1);
Column<int, ContainerType> c4(mc, pV2);
Poco::Data::swap(c3, c4);
assert (c3[0] == 5);
assert (c3[1] == 4);
assert (c3[2] == 3);
assert (c3[3] == 2);
assert (c3[4] == 1);
assert (c4[0] == 1);
assert (c4[1] == 2);
assert (c4[2] == 3);
assert (c4[3] == 4);
assert (c4[4] == 5);
std::swap(c3, c4);
assert (c3[0] == 1);
assert (c3[1] == 2);
assert (c3[2] == 3);
assert (c3[3] == 4);
assert (c3[4] == 5);
assert (c4[0] == 5);
assert (c4[1] == 4);
assert (c4[2] == 3);
assert (c4[3] == 2);
assert (c4[4] == 1);
}