about summary refs log tree commit diff stats
path: root/010vm.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-02-06 23:05:33 -0800
committerKartik K. Agaram <vc@akkartik.com>2017-02-06 23:05:33 -0800
commit6078ecf1f67c0ff0089d58c8b9c11ec8230e9238 (patch)
tree7695b059eb26a68af181d48dfba3c5dba51cbbdc /010vm.cc
parent79acb7305616f9cdb8a400cac40ed8034413b79e (diff)
downloadmu-6078ecf1f67c0ff0089d58c8b9c11ec8230e9238.tar.gz
3741
Eliminate a long-standing under-abstraction.
Diffstat (limited to '010vm.cc')
-rw-r--r--010vm.cc32
1 files changed, 20 insertions, 12 deletions
diff --git a/010vm.cc b/010vm.cc
index 92384f02..b35d39d8 100644
--- a/010vm.cc
+++ b/010vm.cc
@@ -366,10 +366,9 @@ reagent::reagent(const reagent& other) {
   value = other.value;
   initialized = other.initialized;
   for (int i = 0;  i < SIZE(other.properties);  ++i) {
-    properties.push_back(pair<string, string_tree*>(other.properties.at(i).first,
-                                                    other.properties.at(i).second ? new string_tree(*other.properties.at(i).second) : NULL));
+    properties.push_back(pair<string, string_tree*>(other.properties.at(i).first, copy(other.properties.at(i).second)));
   }
-  type = other.type ? new type_tree(*other.type) : NULL;
+  type = copy(other.type);
   // End reagent Copy Constructor
 }
 
@@ -377,8 +376,8 @@ type_tree::type_tree(const type_tree& original) {
   atom = original.atom;
   name = original.name;
   value = original.value;
-  left = original.left ? new type_tree(*original.left) : NULL;
-  right = original.right ? new type_tree(*original.right) : NULL;
+  left = copy(original.left);
+  right = copy(original.right);
 }
 
 type_tree& type_tree::operator=(const type_tree& original) {
@@ -386,9 +385,9 @@ type_tree& type_tree::operator=(const type_tree& original) {
   name = original.name;
   value = original.value;
   if (left) delete left;
-  left = original.left ? new type_tree(*original.left) : NULL;
+  left = copy(original.left);
   if (right) delete right;
-  right = original.right ? new type_tree(*original.right) : NULL;
+  right = copy(original.right);
   return *this;
 }
 
@@ -471,8 +470,8 @@ void test_compare_list_with_smaller_left_but_larger_right_identical_types() {
 string_tree::string_tree(const string_tree& original) {
   atom = original.atom;
   value = original.value;
-  left = original.left ? new string_tree(*original.left) : NULL;
-  right = original.right ? new string_tree(*original.right) : NULL;
+  left = copy(original.left);
+  right = copy(original.right);
 }
 
 reagent& reagent::operator=(const reagent& other) {
@@ -481,13 +480,12 @@ reagent& reagent::operator=(const reagent& other) {
     if (properties.at(i).second) delete properties.at(i).second;
   properties.clear();
   for (int i = 0;  i < SIZE(other.properties);  ++i)
-    properties.push_back(pair<string, string_tree*>(other.properties.at(i).first,
-                                                    other.properties.at(i).second ? new string_tree(*other.properties.at(i).second) : NULL));
+    properties.push_back(pair<string, string_tree*>(other.properties.at(i).first, copy(other.properties.at(i).second)));
   name = other.name;
   value = other.value;
   initialized = other.initialized;
   if (type) delete type;
-  type = other.type ? new type_tree(*other.type) : NULL;
+  type = copy(other.type);
   // End reagent Copy Operator
   return *this;
 }
@@ -563,6 +561,16 @@ string_tree* property(const reagent& r, const string& name) {
   return NULL;
 }
 
+string_tree* copy(const string_tree* x) {
+  if (x == NULL) return NULL;
+  return new string_tree(*x);
+}
+
+type_tree* copy(const type_tree* x) {
+  if (x == NULL) return NULL;
+  return new type_tree(*x);
+}
+
 :(before "End Globals")
 extern const string Ignore(",");  // commas are ignored in Mu except within [] strings
 :(code)