summaryrefslogtreecommitdiff
path: root/ext/ODBM_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/ODBM_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/ODBM_File')
-rw-r--r--ext/ODBM_File/ODBM_File.xs55
-rw-r--r--ext/ODBM_File/typemap12
2 files changed, 23 insertions, 44 deletions
diff --git a/ext/ODBM_File/ODBM_File.xs b/ext/ODBM_File/ODBM_File.xs
index 2d67f99f5c..463f8e8615 100644
--- a/ext/ODBM_File/ODBM_File.xs
+++ b/ext/ODBM_File/ODBM_File.xs
@@ -37,12 +37,14 @@ datum nextkey(datum key);
#include <fcntl.h>
+#define fetch_key 0
+#define store_key 1
+#define fetch_value 2
+#define store_value 3
+
typedef struct {
void * dbp ;
- SV * filter_fetch_key ;
- SV * filter_store_key ;
- SV * filter_fetch_value ;
- SV * filter_store_value ;
+ SV * filter[4];
int filtering ;
} ODBM_File_type;
@@ -118,17 +120,14 @@ DESTROY(db)
ODBM_File db
PREINIT:
dMY_CXT;
+ int i = store_value;
CODE:
dbmrefcnt--;
dbmclose();
- 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);
datum_value
@@ -189,30 +188,10 @@ filter_fetch_key(db, code)
ODBM_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
+ ALIAS:
+ ODBM_File::filter_fetch_key = fetch_key
+ ODBM_File::filter_store_key = store_key
+ ODBM_File::filter_fetch_value = fetch_value
+ ODBM_File::filter_store_value = store_value
CODE:
- DBM_setFilter(db->filter_fetch_key, code) ;
-
-SV *
-filter_store_key(db, code)
- ODBM_File db
- SV * code
- SV * RETVAL = &PL_sv_undef ;
- CODE:
- DBM_setFilter(db->filter_store_key, code) ;
-
-SV *
-filter_fetch_value(db, code)
- ODBM_File db
- SV * code
- SV * RETVAL = &PL_sv_undef ;
- CODE:
- DBM_setFilter(db->filter_fetch_value, code) ;
-
-SV *
-filter_store_value(db, code)
- ODBM_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/ODBM_File/typemap b/ext/ODBM_File/typemap
index 68313c346e..d1f16b4d2c 100644
--- a/ext/ODBM_File/typemap
+++ b/ext/ODBM_File/typemap
@@ -18,7 +18,7 @@ INPUT
T_DATUM_K
{
STRLEN len;
- DBM_ckFilter($arg, filter_store_key, \"filter_store_key\");
+ DBM_ckFilter($arg, filter[store_key], \"filter_store_key\");
$var.dptr = SvPVbyte($arg, len);
$var.dsize = (int)len;
}
@@ -26,9 +26,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;
@@ -36,7 +36,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);
@@ -51,9 +51,9 @@ T_GDATUM
OUTPUT
T_DATUM_K
sv_setpvn($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
sv_setpvn($arg, $var.dptr, $var.dsize);
- DBM_ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
+ DBM_ckFilter($arg, filter[fetch_value],\"filter_fetch_value\");
T_GDATUM
sv_usepvn($arg, $var.dptr, $var.dsize);