mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 11:05:03 +02:00
removed Var iterators, fixed SOO alignment
- removed unnecessary using directives in Data library - removed iterator pointers from Var (reduce size, always return copy) - added Alignment header (adapted from LLVM infrastructure) - added alignment guards to SOO implementations
This commit is contained in:
@@ -40,10 +40,13 @@
|
||||
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/MetaProgramming.h"
|
||||
#include "Poco/Alignment.h"
|
||||
#include <algorithm>
|
||||
#include <typeinfo>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef POCO_ENABLE_CPP11
|
||||
#include <type_traits>
|
||||
#endif
|
||||
|
||||
namespace Poco {
|
||||
|
||||
@@ -64,7 +67,7 @@ template <class> class VarHolderImpl;
|
||||
template <typename PlaceholderT, unsigned int SizeV = POCO_SMALL_OBJECT_SIZE>
|
||||
union Placeholder
|
||||
/// ValueHolder union (used by Poco::Any and Poco::Dynamic::Var for small
|
||||
/// object optimization).
|
||||
/// object optimization, when enabled).
|
||||
///
|
||||
/// If Holder<Type> fits into POCO_SMALL_OBJECT_SIZE bytes of storage,
|
||||
/// it will be placement-new-allocated into the local buffer
|
||||
@@ -86,23 +89,23 @@ public:
|
||||
|
||||
void erase()
|
||||
{
|
||||
std::memset(holder, 0, sizeof(Placeholder));
|
||||
std::memset(holder.h, 0, sizeof(Placeholder));
|
||||
}
|
||||
|
||||
bool isLocal() const
|
||||
{
|
||||
return holder[SizeV] != 0;
|
||||
return holder.h[SizeV] != 0;
|
||||
}
|
||||
|
||||
void setLocal(bool local) const
|
||||
{
|
||||
holder[SizeV] = local ? 1 : 0;
|
||||
holder.h[SizeV] = local ? 1 : 0;
|
||||
}
|
||||
|
||||
PlaceholderT* content() const
|
||||
{
|
||||
if(isLocal())
|
||||
return reinterpret_cast<PlaceholderT*>(holder);
|
||||
return reinterpret_cast<PlaceholderT*>(holder.h);
|
||||
else
|
||||
return pHolder;
|
||||
}
|
||||
@@ -112,9 +115,16 @@ public:
|
||||
private:
|
||||
#endif
|
||||
|
||||
PlaceholderT* pHolder;
|
||||
PlaceholderT* pHolder;
|
||||
#ifndef POCO_NO_SOO
|
||||
mutable unsigned char holder[SizeV + 1];
|
||||
#ifndef POCO_ENABLE_CPP11
|
||||
#error "Any SOO can only be enabled with C++11 support"
|
||||
#endif
|
||||
mutable union
|
||||
{
|
||||
std::aligned_storage<SizeV + 1> a;
|
||||
unsigned char h[SizeV + 1];
|
||||
} holder;
|
||||
#endif
|
||||
|
||||
friend class Any;
|
||||
@@ -130,7 +140,7 @@ private:
|
||||
template <typename PlaceholderT>
|
||||
union Placeholder
|
||||
/// ValueHolder union (used by Poco::Any and Poco::Dynamic::Var for small
|
||||
/// object optimization).
|
||||
/// object optimization, when enabled).
|
||||
///
|
||||
/// If Holder<Type> fits into POCO_SMALL_OBJECT_SIZE bytes of storage,
|
||||
/// it will be placement-new-allocated into the local buffer
|
||||
@@ -275,7 +285,7 @@ public:
|
||||
/// Returns true if the Any is empty.
|
||||
{
|
||||
char buf[POCO_SMALL_OBJECT_SIZE] = { 0 };
|
||||
return 0 == std::memcmp(_valueHolder.holder, buf, POCO_SMALL_OBJECT_SIZE);
|
||||
return 0 == std::memcmp(_valueHolder.holder.h, buf, POCO_SMALL_OBJECT_SIZE);
|
||||
}
|
||||
|
||||
const std::type_info & type() const
|
||||
@@ -318,7 +328,7 @@ private:
|
||||
{
|
||||
if ((sizeof(Holder<ValueType>) <= POCO_SMALL_OBJECT_SIZE))
|
||||
{
|
||||
new ((ValueHolder*) pPlaceholder->holder) Holder(_held);
|
||||
new ((ValueHolder*) pPlaceholder->holder.h) Holder(_held);
|
||||
pPlaceholder->setLocal(true);
|
||||
}
|
||||
else
|
||||
@@ -344,7 +354,7 @@ private:
|
||||
{
|
||||
if (sizeof(Holder<ValueType>) <= Placeholder<ValueType>::Size::value)
|
||||
{
|
||||
new (reinterpret_cast<ValueHolder*>(_valueHolder.holder)) Holder<ValueType>(value);
|
||||
new (reinterpret_cast<ValueHolder*>(_valueHolder.holder.h)) Holder<ValueType>(value);
|
||||
_valueHolder.setLocal(true);
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user