improved SOO swap, fixed Darwin-clang build config

This commit is contained in:
Aleksandar Fabijanic
2013-03-31 16:28:53 -05:00
parent 6b871a8cab
commit 1f4afb9c6c
4 changed files with 37 additions and 16 deletions

View File

@@ -33,7 +33,7 @@ Release 1.5.2 (2013-03-??)
- fixed GH #131: no timezone global var on OpenBSD - fixed GH #131: no timezone global var on OpenBSD
- fixed GH #102: Some subprojects don't have x64 solutions for VS 2010 - fixed GH #102: Some subprojects don't have x64 solutions for VS 2010
- added GH #75: Poco::Uri addQueryParameter method - added GH #75: Poco::Uri addQueryParameter method
- Poco::Environment::osDisplayName() now recognized Windows 8/Server 2012 - Poco::Environment::osDisplayName() now recognizes Windows 8/Server 2012
- fixed GH #140: Poco::Runnable threading cleanup issue - fixed GH #140: Poco::Runnable threading cleanup issue
- simplified default TCP/HTTPServer construction - simplified default TCP/HTTPServer construction
- fixed GH #141: Application::run() documentation/implementation discrepancy - fixed GH #141: Application::run() documentation/implementation discrepancy

View File

@@ -106,9 +106,9 @@ public:
return pHolder; return pHolder;
} }
// MSVC71 doesn't extend friendship to nested class (Any::Holder) // MSVC71,80 won't extend friendship to nested class (Any::Holder)
#if !defined(POCO_MSVC_VERSION) || (defined(POCO_MSVC_VERSION) && (POCO_MSVC_VERSION > 71)) #if !defined(POCO_MSVC_VERSION) || (defined(POCO_MSVC_VERSION) && (POCO_MSVC_VERSION > 80))
private: // private:
#endif #endif
PlaceholderT* pHolder; PlaceholderT* pHolder;
@@ -165,7 +165,7 @@ public:
if(!empty()) if(!empty())
{ {
if(_valueHolder.isLocal()) if(_valueHolder.isLocal())
content()->~ValueHolder(); destruct();
else else
delete content(); delete content();
} }
@@ -174,9 +174,9 @@ public:
Any& swap(Any& other) Any& swap(Any& other)
/// Swaps the content of the two Anys. /// Swaps the content of the two Anys.
/// ///
/// When small object optimizaton is enabled, /// When small object optimizaton is enabled, swap only
/// swap is only exception-safe when both (*this and /// has no-throw guarantee when both (*this and other)
/// other) objects are allocated on the heap. /// objects are allocated on the heap.
{ {
if (this == &other) return *this; if (this == &other) return *this;
@@ -187,16 +187,24 @@ public:
else else
{ {
Any tmp(*this); Any tmp(*this);
if (_valueHolder.isLocal()) this->~Any(); try
construct(other); {
other = tmp; if (_valueHolder.isLocal()) destruct();
construct(other);
other = tmp;
}
catch (...)
{
construct(tmp);
throw;
}
} }
return *this; return *this;
} }
template<typename ValueType> template<typename ValueType>
Any & operator = (const ValueType& rhs) Any& operator = (const ValueType& rhs)
/// Assignment operator for all types != Any. /// Assignment operator for all types != Any.
/// ///
/// Example: /// Example:
@@ -309,6 +317,11 @@ private:
_valueHolder.erase(); _valueHolder.erase();
} }
void destruct()
{
content()->~ValueHolder();
}
Placeholder<ValueHolder> _valueHolder; Placeholder<ValueHolder> _valueHolder;

View File

@@ -668,9 +668,17 @@ inline void Var::swap(Var& other)
else else
{ {
Var tmp(*this); Var tmp(*this);
if (_placeholder.isLocal()) destruct(); try
construct(other); {
other = tmp; if (_placeholder.isLocal()) destruct();
construct(other);
other = tmp;
}
catch (...)
{
construct(tmp);
throw;
}
} }
#endif #endif

View File

@@ -33,7 +33,7 @@ LINK = $(CXX) -bind_at_load
LIB = libtool -static -o LIB = libtool -static -o
RANLIB = ranlib RANLIB = ranlib
SHLIB = $(CXX) -dynamiclib -o $@ SHLIB = $(CXX) -dynamiclib -o $@
DYLIB = $(CXX) -dynamic -bundle $(RORELOCS) suppress -Wl,-bind_at_load -o $@ DYLIB = $(CXX) -dynamic -bundle $(RORELOCS) -Wl,-bind_at_load -o $@
SHLIBLN = $(POCO_BASE)/build/script/shlibln SHLIBLN = $(POCO_BASE)/build/script/shlibln
STRIP = STRIP =
DEP = $(POCO_BASE)/build/script/makedepend.clang DEP = $(POCO_BASE)/build/script/makedepend.clang