Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 392ffe1

Browse files
glebmxzyfer
authored andcommitted
SharedPtr: More cleanup
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`.
1 parent a8273fc commit 392ffe1

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

src/memory/SharedPtr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ namespace Sass {
6262
// AST_Node_Ptr ast = dynamic_cast<AST_Node*>(node);
6363
if (node->dbg) std::cerr << "DELETE NODE " << node << "\n";
6464
#endif
65-
delete(node);
65+
delete node;
66+
node = NULL;
6667
}
6768
}
6869
}

src/memory/SharedPtr.hpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace Sass {
4848
size_t line;
4949
#endif
5050
static bool taint;
51-
long refcounter;
51+
size_t refcounter;
5252
#ifdef DEBUG_SHARED_PTR
5353
bool dbg;
5454
#endif
@@ -72,6 +72,9 @@ namespace Sass {
7272
void setDbg(bool dbg) {
7373
this->dbg = dbg;
7474
}
75+
size_t getRefCount() const {
76+
return refcounter;
77+
}
7578
#endif
7679
static void setTaint(bool val) {
7780
taint = val;
@@ -80,9 +83,6 @@ namespace Sass {
8083
virtual const std::string to_string() const = 0;
8184

8285
virtual ~SharedObj();
83-
long getRefCount() const {
84-
return refcounter;
85-
}
8686
};
8787

8888

@@ -115,9 +115,6 @@ namespace Sass {
115115
SharedObj* operator-> () const {
116116
return node;
117117
};
118-
bool isNull () {
119-
return node == NULL;
120-
};
121118
bool isNull () const {
122119
return node == NULL;
123120
};
@@ -179,6 +176,8 @@ namespace Sass {
179176

180177
~SharedImpl() {};
181178
public:
179+
using SharedPtr::isNull;
180+
using SharedPtr::operator bool;
182181
operator T*() const {
183182
return static_cast<T*>(this->obj());
184183
}
@@ -197,15 +196,6 @@ namespace Sass {
197196
T* detach() {
198197
return static_cast<T*>(SharedPtr::detach());
199198
}
200-
bool isNull() const {
201-
return this->obj() == NULL;
202-
}
203-
bool operator<(const T& rhs) const {
204-
return *this->ptr() < rhs;
205-
};
206-
operator bool() const {
207-
return this->obj() != NULL;
208-
};
209199
};
210200

211201
}

0 commit comments

Comments
 (0)