Commit 63619877 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Use a static jump table for the cursors.

parent b4f9d546
......@@ -51,11 +51,7 @@ typedef int vslc_skip_f(void *, ssize_t words);
typedef int vslc_ref_f(void *, struct vslc_shmptr *ptr);
typedef int vslc_check_f(const void *, const struct VSLC_ptr *ptr);
struct vslc {
struct VSL_cursor c;
unsigned magic;
#define VSLC_MAGIC 0x5007C0DE
struct vslc_tbl {
vslc_delete_f *delete;
vslc_next_f *next;
vslc_reset_f *reset;
......@@ -63,6 +59,14 @@ struct vslc {
vslc_check_f *check;
};
struct vslc {
struct VSL_cursor c;
unsigned magic;
#define VSLC_MAGIC 0x5007C0DE
const struct vslc_tbl *tbl;
};
struct VSL_data {
unsigned magic;
#undef VSL_MAGIC
......
......@@ -212,6 +212,14 @@ vslc_vsm_skip(void *cursor, ssize_t words)
return (0);
}
static struct vslc_tbl vslc_vsm_tbl = {
.delete = vslc_vsm_delete,
.next = vslc_vsm_next,
.reset = vslc_vsm_reset,
.skip = vslc_vsm_skip,
.check = vslc_vsm_check,
};
struct VSL_cursor *
VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, int tail)
{
......@@ -245,11 +253,7 @@ VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, int tail)
c->c.c.vxid = -1; /* N/A to this cursor type */
c->c.c.shmptr_ok = 1;
c->c.magic = VSLC_MAGIC;
c->c.delete = vslc_vsm_delete;
c->c.next = vslc_vsm_next;
c->c.reset = vslc_vsm_reset;
c->c.skip = vslc_vsm_skip;
c->c.check = vslc_vsm_check;
c->c.tbl = & vslc_vsm_tbl;
c->vsm = vsm;
c->vf = vf;
......@@ -356,6 +360,14 @@ vslc_file_reset(void *cursor)
return (-1);
}
static struct vslc_tbl vslc_file_tbl = {
.delete = vslc_file_delete,
.next = vslc_file_next,
.reset = vslc_file_reset,
.skip = NULL,
.check = NULL,
};
struct VSL_cursor *
VSL_CursorFile(struct VSL_data *vsl, const char *name)
{
......@@ -399,9 +411,7 @@ VSL_CursorFile(struct VSL_data *vsl, const char *name)
}
c->c.c.vxid = -1; /* N/A to this cursor type */
c->c.magic = VSLC_MAGIC;
c->c.delete = vslc_file_delete;
c->c.next = vslc_file_next;
c->c.reset = vslc_file_reset;
c->c.tbl = &vslc_file_tbl;
c->fd = fd;
c->buflen = BUFSIZ;
......@@ -417,9 +427,9 @@ VSL_DeleteCursor(struct VSL_cursor *cursor)
struct vslc *c;
CAST_OBJ_NOTNULL(c, (void *)cursor, VSLC_MAGIC);
if (c->delete == NULL)
if (c->tbl->delete == NULL)
return;
(c->delete)(c);
(c->tbl->delete)(c);
}
int
......@@ -428,9 +438,9 @@ VSL_ResetCursor(struct VSL_cursor *cursor)
struct vslc *c;
CAST_OBJ_NOTNULL(c, (void *)cursor, VSLC_MAGIC);
if (c->reset == NULL)
if (c->tbl->reset == NULL)
return (-1);
return ((c->reset)(c));
return ((c->tbl->reset)(c));
}
int
......@@ -439,8 +449,8 @@ VSL_Next(struct VSL_cursor *cursor)
struct vslc *c;
CAST_OBJ_NOTNULL(c, (void *)cursor, VSLC_MAGIC);
AN(c->next);
return ((c->next)(c));
AN(c->tbl->next);
return ((c->tbl->next)(c));
}
int
......@@ -449,9 +459,9 @@ vsl_skip(struct VSL_cursor *cursor, ssize_t words)
struct vslc *c;
CAST_OBJ_NOTNULL(c, (void *)cursor, VSLC_MAGIC);
if (c->skip == NULL)
if (c->tbl->skip == NULL)
return (-1);
return ((c->skip)(c, words));
return ((c->tbl->skip)(c, words));
}
int
......@@ -460,7 +470,7 @@ VSL_Check(const struct VSL_cursor *cursor, const struct VSLC_ptr *ptr)
const struct vslc *c;
CAST_OBJ_NOTNULL(c, (const void *)cursor, VSLC_MAGIC);
if (c->check == NULL)
if (c->tbl->check == NULL)
return (-1);
return ((c->check)(c, ptr));
return ((c->tbl->check)(c, ptr));
}
......@@ -203,6 +203,14 @@ vslc_raw_reset(void *cursor)
return (0);
}
static struct vslc_tbl vslc_raw_tbl = {
.delete = NULL,
.next = vslc_raw_next,
.reset = vslc_raw_reset,
.skip = NULL,
.check = NULL,
};
static int
vslc_vtx_next(void *cursor)
{
......@@ -235,6 +243,14 @@ vslc_vtx_reset(void *cursor)
return (0);
}
static struct vslc_tbl vslc_vtx_tbl = {
.delete = NULL,
.next = vslc_vtx_next,
.reset = vslc_vtx_reset,
.skip = NULL,
.check = NULL,
};
static void
vslc_vtx_setup(struct vslc_vtx *c, struct vtx *vtx, unsigned level)
{
......@@ -245,8 +261,7 @@ vslc_vtx_setup(struct vslc_vtx *c, struct vtx *vtx, unsigned level)
c->c.c.vxid = vtx->key.vxid;
c->c.c.level = level;
c->c.magic = VSLC_MAGIC;
c->c.next = vslc_vtx_next;
c->c.reset = vslc_vtx_reset;
c->c.tbl = &vslc_vtx_tbl;
c->magic = VSLC_VTX_MAGIC;
c->vtx = vtx;
......@@ -780,8 +795,7 @@ vslq_raw(struct VSLQ *vslq, VSLQ_dispatch_f *func, void *priv)
memset(&rawc, 0, sizeof rawc);
rawc.c.c.vxid = -1;
rawc.c.magic = VSLC_MAGIC;
rawc.c.next = vslc_raw_next;
rawc.c.reset = vslc_raw_reset;
rawc.c.tbl = &vslc_raw_tbl;
rawc.magic = VSLC_RAW_MAGIC;
pc[0] = &rawc.c.c;
pc[1] = 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