diff --git a/src/memory/SharedPtr.cpp b/src/memory/SharedPtr.cpp index 2530360a5..b4f5ef48b 100644 --- a/src/memory/SharedPtr.cpp +++ b/src/memory/SharedPtr.cpp @@ -32,12 +32,11 @@ namespace Sass { bool SharedObj::taint = false; SharedObj::SharedObj() - : detached(false) + : refcounter(0) #ifdef DEBUG_SHARED_PTR , dbg(false) #endif { - refcounter = 0; #ifdef DEBUG_SHARED_PTR if (taint) all.push_back(this); #endif @@ -63,9 +62,7 @@ namespace Sass { // AST_Node_Ptr ast = dynamic_cast(node); if (node->dbg) std::cerr << "DELETE NODE " << node << "\n"; #endif - if (!node->detached) { - delete(node); - } + delete(node); } } } @@ -73,7 +70,6 @@ namespace Sass { void SharedPtr::incRefCount() { if (node) { ++ node->refcounter; - node->detached = false; #ifdef DEBUG_SHARED_PTR if (node->dbg) { std::cerr << "+ " << node << " X " << node->refcounter << " (" << this << ") " << "\n"; @@ -111,4 +107,4 @@ namespace Sass { incRefCount(); } -} \ No newline at end of file +} diff --git a/src/memory/SharedPtr.hpp b/src/memory/SharedPtr.hpp index 7e13bf06c..fbfd00312 100644 --- a/src/memory/SharedPtr.hpp +++ b/src/memory/SharedPtr.hpp @@ -49,8 +49,6 @@ namespace Sass { #endif static bool taint; long refcounter; - // long refcount; - bool detached; #ifdef DEBUG_SHARED_PTR bool dbg; #endif @@ -82,7 +80,7 @@ namespace Sass { virtual const std::string to_string() const = 0; virtual ~SharedObj(); - long getRefCount() { + long getRefCount() const { return refcounter; } }; @@ -123,11 +121,10 @@ namespace Sass { bool isNull () const { return node == NULL; }; - SharedObj* detach() const { - if (node) { - node->detached = true; - } - return node; + SharedObj* detach() { + SharedObj* result = node; + node = NULL; + return result; }; operator bool() const { return node != NULL; @@ -197,8 +194,7 @@ namespace Sass { T* ptr () const { return static_cast(this->obj()); }; - T* detach() const { - if (this->obj() == NULL) return NULL; + T* detach() { return static_cast(SharedPtr::detach()); } bool isNull() const { @@ -214,4 +210,4 @@ namespace Sass { } -#endif \ No newline at end of file +#endif