{
MemoryContext parent = context->parent;
- if (context == parent->firstchild)
- parent->firstchild = context->nextchild;
+ if (context->prevchild != NULL)
+ context->prevchild->nextchild = context->nextchild;
else
{
- MemoryContext child;
-
- for (child = parent->firstchild; child; child = child->nextchild)
- {
- if (context == child->nextchild)
- {
- child->nextchild = context->nextchild;
- break;
- }
- }
+ Assert(parent->firstchild == context);
+ parent->firstchild = context->nextchild;
}
+
+ if (context->nextchild != NULL)
+ context->nextchild->prevchild = context->prevchild;
}
/* And relink */
{
AssertArg(MemoryContextIsValid(new_parent));
context->parent = new_parent;
+ context->prevchild = NULL;
context->nextchild = new_parent->firstchild;
+ if (new_parent->firstchild != NULL)
+ new_parent->firstchild->prevchild = context;
new_parent->firstchild = context;
}
else
{
context->parent = NULL;
+ context->prevchild = NULL;
context->nextchild = NULL;
}
}
node->methods = methods;
node->parent = NULL; /* for the moment */
node->firstchild = NULL;
+ node->prevchild = NULL;
node->nextchild = NULL;
node->isReset = true;
node->name = ((char *) node) + size;
{
node->parent = parent;
node->nextchild = parent->firstchild;
+ if (parent->firstchild != NULL)
+ parent->firstchild->prevchild = node;
parent->firstchild = node;
/* inherit allowInCritSection flag from parent */
node->allowInCritSection = parent->allowInCritSection;
MemoryContextMethods *methods; /* virtual function table */
MemoryContext parent; /* NULL if no parent (toplevel context) */
MemoryContext firstchild; /* head of linked list of children */
+ MemoryContext prevchild; /* previous child of same parent */
MemoryContext nextchild; /* next child of same parent */
char *name; /* context name (just for debugging) */
MemoryContextCallback *reset_cbs; /* list of reset/delete callbacks */