Permalink
Browse files

Just ref the children and roll.

  • Loading branch information...
1 parent 86aa696 commit 187014ce7f1570c0155da3aa34ef7c7b75069ac6 @toddsundsted committed Apr 21, 2012
Showing with 16 additions and 26 deletions.
  1. +8 −0 db.h
  2. +6 −0 db_objects.c
  3. +2 −26 objects.c
View
@@ -138,6 +138,14 @@ extern int db_object_bytes(Objid);
* properties.
*/
+extern Var db_children(Objid);
+ /* Returns a list of the children of the
+ * given object. db_children() does not/
+ * can not free the returned list. The caller
+ * should therefore free it once it has finished
+ * operating on it.
+ */
+
extern Var db_ancestors(Objid, bool);
/* Returns a list of the ancestors of the
* given object. db_ancestors() does not/
View
@@ -501,6 +501,12 @@ db_for_all_children(Objid oid, int (*func) (void *, Objid), void *data)
return 0;
}
+Var
+db_children(Objid oid)
+{
+ return var_ref(objects[oid]->children);
+}
+
static int
check_for_duplicate_parents(Var parents)
{
View
@@ -479,23 +479,6 @@ bf_parents(Var arglist, Byte next, void *vdata, Objid progr)
}
}
-struct children_data {
- Var r;
- int i;
-};
-
-static int
-add_to_list(void *data, Objid child)
-{
- struct children_data *d = data;
-
- d->i++;
- d->r.v.list[d->i].type = TYPE_OBJ;
- d->r.v.list[d->i].v.obj = child;
-
- return 0;
-}
-
static package
bf_children(Var arglist, Byte next, void *vdata, Objid progr)
{ /* (object) */
@@ -505,15 +488,8 @@ bf_children(Var arglist, Byte next, void *vdata, Objid progr)
if (!valid(oid))
return make_error_pack(E_INVARG);
- else {
- struct children_data d;
-
- d.r = new_list(db_count_children(oid));
- d.i = 0;
- db_for_all_children(oid, add_to_list, &d);
-
- return make_var_pack(d.r);
- }
+ else
+ return make_var_pack(db_children(oid));
}
static package

0 comments on commit 187014c

Please sign in to comment.