about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/nixexpr.cc37
-rw-r--r--src/libexpr/nixexpr.hh5
2 files changed, 36 insertions, 6 deletions
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index 2c49ecd05100..5c67b74ca6c6 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -7,6 +7,7 @@
 
 
 ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct)
+    : table(0)
 {
     this->maxLoadPct = maxLoadPct;
     table = ATtableCreate(initialSize, maxLoadPct);
@@ -17,6 +18,36 @@ ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct)
 ATermMap::ATermMap(const ATermMap & map)
     : table(0)
 {
+    copy(map);
+}
+
+
+ATermMap::~ATermMap()
+{
+    free();
+}
+
+
+ATermMap & ATermMap::operator = (const ATermMap & map)
+{
+    if (this == &map) return *this;
+    free();
+    copy(map);
+    return *this;
+}
+
+
+void ATermMap::free()
+{
+    if (table) {
+        ATtableDestroy(table);
+        table = 0;
+    }
+}
+
+
+void ATermMap::copy(const ATermMap & map)
+{
     ATermList keys = map.keys();
 
     /* !!! adjust allocation for load pct */
@@ -28,12 +59,6 @@ ATermMap::ATermMap(const ATermMap & map)
 }
 
 
-ATermMap::~ATermMap()
-{
-    if (table) ATtableDestroy(table);
-}
-
-
 void ATermMap::set(ATerm key, ATerm value)
 {
     return ATtablePut(table, key, value);
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index b7decaa3d953..fa3815216f36 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -29,6 +29,8 @@ public:
     ATermMap(const ATermMap & map);
     ~ATermMap();
 
+    ATermMap & ATermMap::operator = (const ATermMap & map);
+        
     void set(ATerm key, ATerm value);
     void set(const string & key, ATerm value);
 
@@ -46,6 +48,9 @@ public:
 
 private:
     void add(const ATermMap & map, ATermList & keys);
+
+    void free();
+    void copy(const ATermMap & map);
 };