MEDIUM: lua: remove hlua_sample_fetch

This struct used to carry only a sample fetch function. Thanks to
lua_pushuserdata(), we don't need to have the Lua engine allocate
that struct for us and we can simply push our pointer onto the stack.
This makes the code more readable by removing several occurrences of
"f->f->". Just like the previous patch, it comes with the nice effect
of saving about 1.3% of performance when fetching samples from Lua.
This commit is contained in:
Willy Tarreau 2015-03-10 14:27:20 +01:00
parent 47860ed505
commit 2ec2274f90
2 changed files with 6 additions and 18 deletions

View File

@ -103,16 +103,6 @@ struct hlua_smp {
int stringsafe; int stringsafe;
}; };
/* This struct is used as a closure argument associated
* with dynamic sample-fetch created fucntions. This contains
* a pointer to the original sample_fetch struct. It is used
* to identify the function to execute with the sample fetch
* wrapper.
*/
struct hlua_sample_fetch {
struct sample_fetch *f;
};
/* This struct contains data used with sleep functions. */ /* This struct contains data used with sleep functions. */
struct hlua_sleep { struct hlua_sleep {
struct task *task; /* task associated with sleep. */ struct task *task; /* task associated with sleep. */

View File

@ -2539,13 +2539,13 @@ static int hlua_fetches_new(lua_State *L, struct hlua_txn *txn, int stringsafe)
__LJMP static int hlua_run_sample_fetch(lua_State *L) __LJMP static int hlua_run_sample_fetch(lua_State *L)
{ {
struct hlua_smp *s; struct hlua_smp *s;
struct hlua_sample_fetch *f; struct sample_fetch *f;
struct arg args[ARGM_NBARGS + 1]; struct arg args[ARGM_NBARGS + 1];
int i; int i;
struct sample smp; struct sample smp;
/* Get closure arguments. */ /* Get closure arguments. */
f = (struct hlua_sample_fetch *)lua_touserdata(L, lua_upvalueindex(1)); f = (struct sample_fetch *)lua_touserdata(L, lua_upvalueindex(1));
/* Get traditionnal arguments. */ /* Get traditionnal arguments. */
s = MAY_LJMP(hlua_checkfetches(L, 1)); s = MAY_LJMP(hlua_checkfetches(L, 1));
@ -2559,10 +2559,10 @@ __LJMP static int hlua_run_sample_fetch(lua_State *L)
args[i].type = ARGT_STOP; args[i].type = ARGT_STOP;
/* Check arguments. */ /* Check arguments. */
MAY_LJMP(hlua_lua2arg_check(L, 1, args, f->f->arg_mask)); MAY_LJMP(hlua_lua2arg_check(L, 1, args, f->arg_mask));
/* Run the special args checker. */ /* Run the special args checker. */
if (f->f->val_args && !f->f->val_args(args, NULL)) { if (f->val_args && !f->val_args(args, NULL)) {
lua_pushfstring(L, "error in arguments"); lua_pushfstring(L, "error in arguments");
WILL_LJMP(lua_error(L)); WILL_LJMP(lua_error(L));
} }
@ -2571,7 +2571,7 @@ __LJMP static int hlua_run_sample_fetch(lua_State *L)
memset(&smp, 0, sizeof(smp)); memset(&smp, 0, sizeof(smp));
/* Run the sample fetch process. */ /* Run the sample fetch process. */
if (!f->f->process(s->p, s->s, s->l7, 0, args, &smp, f->f->kw, f->f->private)) { if (!f->process(s->p, s->s, s->l7, 0, args, &smp, f->kw, f->private)) {
if (s->stringsafe) if (s->stringsafe)
lua_pushstring(L, ""); lua_pushstring(L, "");
else else
@ -3858,7 +3858,6 @@ void hlua_init(void)
int i; int i;
int idx; int idx;
struct sample_fetch *sf; struct sample_fetch *sf;
struct hlua_sample_fetch *hsf;
struct sample_conv *sc; struct sample_conv *sc;
char *p; char *p;
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
@ -3994,8 +3993,7 @@ void hlua_init(void)
/* Register the function. */ /* Register the function. */
lua_pushstring(gL.T, trash.str); lua_pushstring(gL.T, trash.str);
hsf = lua_newuserdata(gL.T, sizeof(struct hlua_sample_fetch)); lua_pushlightuserdata(gL.T, sf);
hsf->f = sf;
lua_pushcclosure(gL.T, hlua_run_sample_fetch, 1); lua_pushcclosure(gL.T, hlua_run_sample_fetch, 1);
lua_settable(gL.T, -3); lua_settable(gL.T, -3);
} }