summaryrefslogtreecommitdiff
path: root/ext/GDBM_File
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2010-10-21 12:27:54 +0200
committerNicholas Clark <nick@ccl4.org>2010-10-21 12:27:54 +0200
commita4051d2977a92b90787a41f76f3ae82ad6401d66 (patch)
tree7e5804c7b148e73304e0fb3b9816354166fbf044 /ext/GDBM_File
parentf4603e303c60a90bd9050fdc96683a33e69bb849 (diff)
downloadperl-a4051d2977a92b90787a41f76f3ae82ad6401d66.tar.gz
In [GNO]DBM_File.xs, store the 4 filter functions as 1 array in the struct.
Previously they were 1 distinct members. Using an array allows the use of a in *_DESTROY, and merging of the 4 XS functions filter_{fetch,store}_{key,value} into 1 body with ALIASes.
Diffstat (limited to 'ext/GDBM_File')
-rw-r--r--ext/GDBM_File/GDBM_File.xs56
-rw-r--r--ext/GDBM_File/typemap12
2 files changed, 24 insertions, 44 deletions
diff --git a/ext/GDBM_File/GDBM_File.xs b/ext/GDBM_File/GDBM_File.xs
index ef951bdd25..5fea3d79bc 100644
--- a/ext/GDBM_File/GDBM_File.xs
+++ b/ext/GDBM_File/GDBM_File.xs
@@ -5,12 +5,14 @@
#include <gdbm.h>
#include <fcntl.h>
+#define fetch_key 0
+#define store_key 1
+#define fetch_value 2
+#define store_value 3
+
typedef struct {
GDBM_FILE dbp ;
- SV * filter_fetch_key ;
- SV * filter_store_key ;
- SV * filter_fetch_value ;
- SV * filter_store_value ;
+ SV * filter[4];
int filtering ;
} GDBM_File_type;
@@ -91,16 +93,14 @@ gdbm_close(db)
void
gdbm_DESTROY(db)
GDBM_File db
+ PREINIT:
+ int i = store_value;
CODE:
gdbm_close(db);
- if (db->filter_fetch_key)
- SvREFCNT_dec(db->filter_fetch_key) ;
- if (db->filter_store_key)
- SvREFCNT_dec(db->filter_store_key) ;
- if (db->filter_fetch_value)
- SvREFCNT_dec(db->filter_fetch_value) ;
- if (db->filter_store_value)
- SvREFCNT_dec(db->filter_store_value) ;
+ do {
+ if (db->filter[i])
+ SvREFCNT_dec(db->filter[i]);
+ } while (i-- > 0);
safefree(db);
#define gdbm_FETCH(db,key) gdbm_fetch(db->dbp,key)
@@ -172,30 +172,10 @@ filter_fetch_key(db, code)
GDBM_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
+ ALIAS:
+ GDBM_File::filter_fetch_key = fetch_key
+ GDBM_File::filter_store_key = store_key
+ GDBM_File::filter_fetch_value = fetch_value
+ GDBM_File::filter_store_value = store_value
CODE:
- DBM_setFilter(db->filter_fetch_key, code) ;
-
-SV *
-filter_store_key(db, code)
- GDBM_File db
- SV * code
- SV * RETVAL = &PL_sv_undef ;
- CODE:
- DBM_setFilter(db->filter_store_key, code) ;
-
-SV *
-filter_fetch_value(db, code)
- GDBM_File db
- SV * code
- SV * RETVAL = &PL_sv_undef ;
- CODE:
- DBM_setFilter(db->filter_fetch_value, code) ;
-
-SV *
-filter_store_value(db, code)
- GDBM_File db
- SV * code
- SV * RETVAL = &PL_sv_undef ;
- CODE:
- DBM_setFilter(db->filter_store_value, code) ;
-
+ DBM_setFilter(db->filter[ix], code);
diff --git a/ext/GDBM_File/typemap b/ext/GDBM_File/typemap
index 71fc285787..d97acd414c 100644
--- a/ext/GDBM_File/typemap
+++ b/ext/GDBM_File/typemap
@@ -15,7 +15,7 @@ FATALFUNC T_OPAQUEPTR
INPUT
T_DATUM_K
- DBM_ckFilter($arg, filter_store_key, \"filter_store_key\");
+ DBM_ckFilter($arg, filter[store_key], \"filter_store_key\");
{
STRLEN len;
$var.dptr = SvPVbyte($arg, len);
@@ -25,9 +25,9 @@ T_DATUM_K_C
{
SV * tmpSV;
STRLEN len;
- if (db->filter_store_key) {
+ if (db->filter[store_key]) {
tmpSV = sv_2mortal(newSVsv($arg));
- DBM_ckFilter(tmpSV, filter_store_key, \"filter_store_key\");
+ DBM_ckFilter(tmpSV, filter[store_key], \"filter_store_key\");
}
else
tmpSV = $arg;
@@ -35,7 +35,7 @@ T_DATUM_K_C
$var.dsize = (int)len;
}
T_DATUM_V
- DBM_ckFilter($arg, filter_store_value, \"filter_store_value\");
+ DBM_ckFilter($arg, filter[store_value], \"filter_store_value\");
if (SvOK($arg)) {
STRLEN len;
$var.dptr = SvPVbyte($arg, len);
@@ -49,9 +49,9 @@ T_DATUM_V
OUTPUT
T_DATUM_K
output_datum(aTHX_ $arg, $var.dptr, $var.dsize);
- DBM_ckFilter($arg, filter_fetch_key,\"filter_fetch_key\");
+ DBM_ckFilter($arg, filter[fetch_key],\"filter_fetch_key\");
T_DATUM_V
output_datum(aTHX_ $arg, $var.dptr, $var.dsize);
- DBM_ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
+ DBM_ckFilter($arg, filter[fetch_value],\"filter_fetch_value\");
T_PTROBJ
sv_setref_pv($arg, dbtype, (void*)$var);