Skip to content

Commit

Permalink
SharedPtr: More cleanup
Browse files Browse the repository at this point in the history
1. Use `size_t` instead of `long` for `refcounter`.
2. Use parent impls for `SharedImpl` where possible.
3. Remove some unused methods.
4. Set `node` to `NULL` after calling `delete`.
  • Loading branch information
glebm authored and xzyfer committed Nov 14, 2018
1 parent a8273fc commit 392ffe1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/memory/SharedPtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ namespace Sass {
// AST_Node_Ptr ast = dynamic_cast<AST_Node*>(node);
if (node->dbg) std::cerr << "DELETE NODE " << node << "\n";
#endif
delete(node);
delete node;
node = NULL;
}
}
}
Expand Down
22 changes: 6 additions & 16 deletions src/memory/SharedPtr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Sass {
size_t line;
#endif
static bool taint;
long refcounter;
size_t refcounter;
#ifdef DEBUG_SHARED_PTR
bool dbg;
#endif
Expand All @@ -72,6 +72,9 @@ namespace Sass {
void setDbg(bool dbg) {
this->dbg = dbg;
}
size_t getRefCount() const {
return refcounter;
}
#endif
static void setTaint(bool val) {
taint = val;
Expand All @@ -80,9 +83,6 @@ namespace Sass {
virtual const std::string to_string() const = 0;

virtual ~SharedObj();
long getRefCount() const {
return refcounter;
}
};


Expand Down Expand Up @@ -115,9 +115,6 @@ namespace Sass {
SharedObj* operator-> () const {
return node;
};
bool isNull () {
return node == NULL;
};
bool isNull () const {
return node == NULL;
};
Expand Down Expand Up @@ -179,6 +176,8 @@ namespace Sass {

~SharedImpl() {};
public:
using SharedPtr::isNull;
using SharedPtr::operator bool;
operator T*() const {
return static_cast<T*>(this->obj());
}
Expand All @@ -197,15 +196,6 @@ namespace Sass {
T* detach() {
return static_cast<T*>(SharedPtr::detach());
}
bool isNull() const {
return this->obj() == NULL;
}
bool operator<(const T& rhs) const {
return *this->ptr() < rhs;
};
operator bool() const {
return this->obj() != NULL;
};
};

}
Expand Down

0 comments on commit 392ffe1

Please sign in to comment.