Merge zizzer:/bk/multiarch
[gem5.git] / base / refcnt.hh
index 251dc905bad2345adf13219a7fb9a86bf6230568..9d9ed4337ada7ed24adf1a853f2767eb29338e6d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002-2004 The Regents of The University of Michigan
+ * Copyright (c) 2002-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -51,15 +51,26 @@ class RefCountingPtr
   protected:
     T *data;
 
-    void copy(T *d) {
+    void copy(T *d)
+    {
         data = d;
         if (data)
             data->incref();
     }
-    void del() {
+    void del()
+    {
         if (data)
             data->decref();
     }
+    void set(T *d)
+    {
+        if (data == d)
+            return;
+
+        del();
+        copy(d);
+    }
+
 
   public:
     RefCountingPtr() : data(NULL) {}
@@ -75,21 +86,9 @@ class RefCountingPtr
     const T &operator*() const { return *data; }
     const T *get() const { return data; }
 
-    RefCountingPtr &operator=(T *p) {
-        if (data != p) {
-            del();
-            copy(p);
-        }
-        return *this;
-    }
-
-    RefCountingPtr &operator=(const RefCountingPtr &r) {
-        if (data != r.data) {
-            del();
-            copy(r.data);
-        }
-        return *this;
-    }
+    RefCountingPtr &operator=(T *p) { set(p); return *this; }
+    RefCountingPtr &operator=(const RefCountingPtr &r)
+    { return operator=(r.data); }
 
     bool operator!() const { return data == 0; }
     operator bool() const { return data != 0; }