Melchior FRANZ wrote:
> Sure. I was you who said we'd be better off reverting. I'm all for
> fixing it.  I just don't know how to do this without breaking
> everything. Or I would have fixed it already.

Give the attached patch a try.  It removed the whole idea of "saving"
removed nodes for future use* and just deletes it for real.  It does
change the order of children in the array, but AFAIK nothing depends
on that.  A cookie to any STL hackers who can tell me a better way to
remove an element from the middle of a vector.

This compiles, but has not been tested.  I just moved to 64 bit linux
on my machine and unfortunately FlightGear isn't happy right now; it
crashes during initialization.

Andy

* Which sounds to me like a bad case of premature optimization.  A
  property node is a comparatively heavy-weight object, and keeping a
  bunch of zombies around is likely to cause as many cache problems as
  it solves allocation ones.  Unless you have benchmarks showing
  something is slow, simpler is always best.  This patch is a net
  removal of code.
Index: props.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/props/props.cxx,v
retrieving revision 1.8
diff -u -r1.8 props.cxx
--- props.cxx	9 May 2005 14:31:41 -0000	1.8
+++ props.cxx	15 May 2005 14:37:38 -0000
@@ -859,17 +859,7 @@
   if (pos >= 0) {
     return _children[pos];
   } else if (create) {
-    SGPropertyNode_ptr node;
-    pos = find_child(name, index, _removedChildren);
-    if (pos >= 0) {
-      vector<SGPropertyNode_ptr>::iterator it = _removedChildren.begin();
-      it += pos;
-      node = _removedChildren[pos];
-      _removedChildren.erase(it);
-      node->setAttribute(REMOVED, false);
-    } else {
-      node = new SGPropertyNode(name, index, this);
-    }
+    SGPropertyNode_ptr node = new SGPropertyNode(name, index, this);
     _children.push_back(node);
     fireChildAdded(node);
     return node;
@@ -920,17 +910,11 @@
   SGPropertyNode_ptr ret;
   int pos = find_child(name, index, _children);
   if (pos >= 0) {
-    vector<SGPropertyNode_ptr>::iterator it = _children.begin();
-    it += pos;
-    SGPropertyNode_ptr node = _children[pos];
-    _children.erase(it);
-    if (keep) {
-      _removedChildren.push_back(node);
-    }
-    node->setAttribute(REMOVED, true);
-    node->clearValue();
-    ret = node;
-    fireChildRemoved(node);
+    ret = _children[pos];
+    _children[pos] = _children[_children.size()-1];
+    _children[_children.size()-1] = ret;
+    _children.erase(_children.end(), _children.end());
+    fireChildRemoved(ret);
   }
   return ret;
 }
_______________________________________________
Flightgear-devel mailing list
[email protected]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d

Reply via email to