Refactor node init

parent bbed74ff
......@@ -198,7 +198,7 @@ vmod_workspace_prealloc(VRT_CTX, VCL_BYTES min_free, VCL_INT max_nodes)
ws_max_nodes = max_nodes;
}
struct node *
static struct node *
node_alloc(struct pesi *pesi)
{
struct node *node;
......@@ -225,6 +225,18 @@ node_alloc(struct pesi *pesi)
return (node);
}
struct node *
node_new(struct pesi *pesi, enum n_type type, enum n_state state)
{
struct node *node;
node = node_alloc(pesi);
AN(node);
node->type = type;
node->state = state;
return (node);
}
static void
node_fini(struct vdp_ctx *vdx, struct node *node)
{
......
......@@ -241,7 +241,7 @@ void node_fill_nodestock(struct ws *, struct node_head *);
//--------------
struct pesi;
struct node *node_alloc(struct pesi *);
struct node *node_new(struct pesi *pesi, enum n_type type, enum n_state state);
void node_insert(const struct bytes_tree *, struct node *, struct node *);
void set_closed(struct bytes_tree *, struct node *);
......
......@@ -500,11 +500,8 @@ pesi_buf_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
VSLdbg(vdx, "bytes_add: adding data to node");
node = node_alloc(pesi);
node = node_new(pesi, T_DATA, ST_DATA);
CHECK_OBJ_NOTNULL(node, NODE_MAGIC);
node->type = T_DATA;
node->state = ST_DATA;
node->data.len = len;
node->data.act = act;
......@@ -634,17 +631,19 @@ bytes_tree_fini(struct bytes_tree *bytes_tree, struct vdp_ctx *vdc)
Lck_Delete(&bytes_tree->nodes_lock);
}
static void
root_node_init(struct node *root_node, struct req *req)
static struct node *
root_node_new(struct pesi *pesi, struct req *req)
{
struct node *root_node;
root_node = node_new(pesi, T_NEXUS, ST_PRIVATE);
CHECK_OBJ_NOTNULL(root_node, NODE_MAGIC);
root_node->state = ST_PRIVATE;
root_node->type = T_NEXUS;
root_node->nexus.req = req;
root_node->nexus.gzip.magic = NEXUS_GZIP_MAGIC;
root_node->nexus.npending_private = 1;
VSTAILQ_INIT(&root_node->nexus.children);
return (root_node);
}
......@@ -724,8 +723,7 @@ vdp_pesi_init(VRT_CTX, struct vdp_ctx *vdc, void **priv, struct objcore *oc)
node_fill_nodestock(req->ws, &pesi->nodestock);
root_node = node_alloc(pesi);
root_node_init(root_node, req);
root_node = root_node_new(pesi, req);
bytes_tree_init(pesi_tasks->bytes_tree, root_node);
......@@ -921,10 +919,8 @@ vdp_pesi_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
if (*pecx->p == VEC_GZ) {
if (parent_gzip == NULL) {
AZ(child);
child = node_alloc(pesi);
child = node_new(pesi, T_CRC, ST_DATA);
CHECK_OBJ_NOTNULL(child, NODE_MAGIC);
child->type = T_CRC;
child->state = ST_DATA;
child->crc.ctype = GZIP_HDR;
node_insert(tree, node, child);
child = NULL;
......@@ -960,10 +956,8 @@ vdp_pesi_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
return (-1);
AZ(child);
child = node_alloc(pesi);
child = node_new(pesi, T_CRC, ST_DATA);
CHECK_OBJ_NOTNULL(child, NODE_MAGIC);
child->type = T_CRC;
child->state = ST_DATA;
child->crc.ctype = UPDATE;
child->crc.icrc = vbe32dec(pecx->p);
child->crc.l_icrc = l;
......@@ -997,10 +991,8 @@ vdp_pesi_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
Debug("INCL [%s][%s] BEGIN\n", q, pecx->p);
AZ(child);
child = node_alloc(pesi);
child = node_new(pesi, T_NEXUS, ST_PRIVATE);
CHECK_OBJ_NOTNULL(child, NODE_MAGIC);
child->type = T_NEXUS;
child->state = ST_PRIVATE;
child->nexus.gzip.magic = NEXUS_GZIP_MAGIC;
node_insert(tree, node, child);
......@@ -1029,10 +1021,8 @@ vdp_pesi_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
case 2:
if (node->nexus.gzip.is) {
AZ(child);
child = node_alloc(pesi);
child = node_new(pesi, T_CRC, ST_DATA);
CHECK_OBJ_NOTNULL(child, NODE_MAGIC);
child->type = T_CRC;
child->state = ST_DATA;
child->crc.ctype = FINAL;
node_insert(tree, node, child);
child = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment