Skip to content

Commit 629bb67

Browse files
authored
Merge pull request #133 from ilmari/hv-fetchs
Use hv_fetchs() instead of hv_fetch() with literal key and manual length
2 parents c2ec112 + 67091ca commit 629bb67

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

DBI.xs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ copy_statement_to_parent(pTHX_ SV *h, imp_xxh_t *imp_xxh)
718718
return;
719719
parent = DBIc_PARENT_H(imp_xxh);
720720
if (parent && SvROK(parent)) {
721-
SV *tmp_sv = *hv_fetch((HV*)SvRV(h), "Statement", 9, 1);
721+
SV *tmp_sv = *hv_fetchs((HV*)SvRV(h), "Statement", 1);
722722
if (SvOK(tmp_sv))
723723
(void)hv_store((HV*)SvRV(parent), "Statement", 9, SvREFCNT_inc(tmp_sv), 0);
724724
}
@@ -754,7 +754,7 @@ set_err_sv(SV *h, imp_xxh_t *imp_xxh, SV *err, SV *errstr, SV *state, SV *method
754754
int err_changed = 0;
755755

756756
if ( DBIc_has(imp_xxh, DBIcf_HandleSetErr)
757-
&& (hook_svp = hv_fetch((HV*)SvRV(h),"HandleSetErr",12,0))
757+
&& (hook_svp = hv_fetchs((HV*)SvRV(h),"HandleSetErr",0))
758758
&& hook_svp
759759
&& ((void)(SvGMAGICAL(*hook_svp) && mg_get(*hook_svp)), SvOK(*hook_svp))
760760
) {
@@ -1107,7 +1107,7 @@ dbih_inner(pTHX_ SV *orv, const char *what)
11071107
if (!SvMAGICAL(ohv)) {
11081108
if (!what)
11091109
return NULL;
1110-
if (!hv_fetch((HV*)ohv,"_NO_DESTRUCT_WARN",17,0))
1110+
if (!hv_fetchs((HV*)ohv,"_NO_DESTRUCT_WARN",0))
11111111
sv_dump(orv);
11121112
croak("%s handle %s is not a DBI handle (has no magic)",
11131113
what, neatsvpv(orv,0));
@@ -1437,7 +1437,7 @@ dbih_setup_handle(pTHX_ SV *orv, char *imp_class, SV *parent, SV *imp_datasv)
14371437
if ( (imp_mem_stash = gv_stashsv(imp_mem_name, FALSE)) == NULL)
14381438
croak(errmsg, neatsvpv(orv,0), SvPVbyte_nolen(imp_mem_name), "unknown _mem package");
14391439

1440-
if ((svp = hv_fetch((HV*)SvRV(h), "dbi_imp_data", 12, 0))) {
1440+
if ((svp = hv_fetchs((HV*)SvRV(h), "dbi_imp_data", 0))) {
14411441
dbi_imp_data = *svp;
14421442
if (SvGMAGICAL(dbi_imp_data)) /* call FETCH via magic */
14431443
mg_get(dbi_imp_data);
@@ -1478,9 +1478,9 @@ dbih_setup_handle(pTHX_ SV *orv, char *imp_class, SV *parent, SV *imp_datasv)
14781478

14791479
/* setup Callbacks from parents' ChildCallbacks */
14801480
if (DBIc_has(parent_imp, DBIcf_Callbacks)
1481-
&& (tmp_svp = hv_fetch((HV*)SvRV(parent), "Callbacks", 9, 0))
1481+
&& (tmp_svp = hv_fetchs((HV*)SvRV(parent), "Callbacks", 0))
14821482
&& SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV
1483-
&& (tmp_svp = hv_fetch((HV*)SvRV(*tmp_svp), "ChildCallbacks", 14, 0))
1483+
&& (tmp_svp = hv_fetchs((HV*)SvRV(*tmp_svp), "ChildCallbacks", 0))
14841484
&& SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV
14851485
) {
14861486
/* XXX mirrors behaviour of dbih_set_attr_k() of Callbacks */
@@ -1493,7 +1493,7 @@ dbih_setup_handle(pTHX_ SV *orv, char *imp_class, SV *parent, SV *imp_datasv)
14931493
if (1) {
14941494
AV *av;
14951495
/* add weakref to new (outer) handle into parents ChildHandles array */
1496-
tmp_svp = hv_fetch((HV*)SvRV(parent), "ChildHandles", 12, 1);
1496+
tmp_svp = hv_fetchs((HV*)SvRV(parent), "ChildHandles", 1);
14971497
if (!SvROK(*tmp_svp)) {
14981498
SV *ChildHandles_rvav = newRV_noinc((SV*)newAV());
14991499
sv_setsv(*tmp_svp, ChildHandles_rvav);
@@ -1523,14 +1523,14 @@ dbih_setup_handle(pTHX_ SV *orv, char *imp_class, SV *parent, SV *imp_datasv)
15231523
case DBIt_DB:
15241524
/* cache _inner_ handle, but also see quick_FETCH */
15251525
(void)hv_store((HV*)SvRV(h), "Driver", 6, newRV_inc(SvRV(parent)), 0);
1526-
(void)hv_fetch((HV*)SvRV(h), "Statement", 9, 1); /* store writable undef */
1526+
(void)hv_fetchs((HV*)SvRV(h), "Statement", 1); /* store writable undef */
15271527
break;
15281528
case DBIt_ST:
15291529
DBIc_NUM_FIELDS((imp_sth_t*)imp) = -1;
15301530
/* cache _inner_ handle, but also see quick_FETCH */
15311531
(void)hv_store((HV*)SvRV(h), "Database", 8, newRV_inc(SvRV(parent)), 0);
15321532
/* copy (alias) Statement from the sth up into the dbh */
1533-
tmp_svp = hv_fetch((HV*)SvRV(h), "Statement", 9, 1);
1533+
tmp_svp = hv_fetchs((HV*)SvRV(h), "Statement", 1);
15341534
(void)hv_store((HV*)SvRV(parent), "Statement", 9, SvREFCNT_inc(*tmp_svp), 0);
15351535
break;
15361536
}
@@ -1638,7 +1638,7 @@ dbih_dumpcom(pTHX_ imp_xxh_t *imp_xxh, const char *msg, int level)
16381638
if (!inner || !SvROK(inner))
16391639
return 1;
16401640
if (DBIc_TYPE(imp_xxh) <= DBIt_DB) {
1641-
SV **svp = hv_fetch((HV*)SvRV(inner), "CachedKids", 10, 0);
1641+
SV **svp = hv_fetchs((HV*)SvRV(inner), "CachedKids", 0);
16421642
if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) {
16431643
HV *hv = (HV*)SvRV(*svp);
16441644
PerlIO_printf(DBILOGFP,"%s CachedKids %d\n", pad, (int)HvKEYS(hv));
@@ -1654,12 +1654,12 @@ dbih_dumpcom(pTHX_ imp_xxh_t *imp_xxh, const char *msg, int level)
16541654
}
16551655
}
16561656
else if (DBIc_TYPE(imp_xxh) == DBIt_DB) {
1657-
SV **svp = hv_fetch((HV*)SvRV(inner), "Name", 4, 0);
1657+
SV **svp = hv_fetchs((HV*)SvRV(inner), "Name", 0);
16581658
if (svp && SvOK(*svp))
16591659
PerlIO_printf(DBILOGFP,"%s Name %s\n", pad, neatsvpv(*svp,0));
16601660
}
16611661
else if (DBIc_TYPE(imp_xxh) == DBIt_ST) {
1662-
SV **svp = hv_fetch((HV*)SvRV(inner), "Statement", 9, 0);
1662+
SV **svp = hv_fetchs((HV*)SvRV(inner), "Statement", 0);
16631663
if (svp && SvOK(*svp))
16641664
PerlIO_printf(DBILOGFP,"%s Statement %s\n", pad, neatsvpv(*svp,0));
16651665
}
@@ -2352,7 +2352,7 @@ dbih_get_attr_k(SV *h, SV *keysv, int dbikey)
23522352
valuesv = &PL_sv_undef;
23532353

23542354
/* fetch from tied outer handle to trigger FETCH magic */
2355-
svp = hv_fetch((HV*)DBIc_MY_H(imp_sth), "NAME",4, FALSE);
2355+
svp = hv_fetchs((HV*)DBIc_MY_H(imp_sth), "NAME", FALSE);
23562356
sv = (svp) ? *svp : &PL_sv_undef;
23572357
if (SvGMAGICAL(sv)) /* call FETCH via magic */
23582358
mg_get(sv);
@@ -2776,7 +2776,7 @@ static void
27762776
clear_cached_kids(pTHX_ SV *h, imp_xxh_t *imp_xxh, const char *meth_name, int trace_level)
27772777
{
27782778
if (DBIc_TYPE(imp_xxh) <= DBIt_DB) {
2779-
SV **svp = hv_fetch((HV*)SvRV(h), "CachedKids", 10, 0);
2779+
SV **svp = hv_fetchs((HV*)SvRV(h), "CachedKids", 0);
27802780
if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) {
27812781
HV *hv = (HV*)SvRV(*svp);
27822782
if (HvKEYS(hv)) {
@@ -2890,7 +2890,7 @@ dbi_profile(SV *h, imp_xxh_t *imp_xxh, SV *statement_sv, SV *method, NV t1, NV t
28902890

28912891
h_hv = (HV*)SvRV(dbih_inner(aTHX_ h, "dbi_profile"));
28922892

2893-
profile = *hv_fetch(h_hv, "Profile", 7, 1);
2893+
profile = *hv_fetchs(h_hv, "Profile", 1);
28942894
if (profile && SvMAGICAL(profile))
28952895
mg_get(profile); /* FETCH */
28962896
if (!profile || !SvROK(profile)) {
@@ -2907,7 +2907,7 @@ dbi_profile(SV *h, imp_xxh_t *imp_xxh, SV *statement_sv, SV *method, NV t1, NV t
29072907
/* statement_sv: undef = use $h->{Statement}, "" (&sv_no) = use empty string */
29082908

29092909
if (!SvOK(statement_sv)) {
2910-
SV **psv = hv_fetch(h_hv, "Statement", 9, 0);
2910+
SV **psv = hv_fetchs(h_hv, "Statement", 0);
29112911
statement_sv = (psv && SvOK(*psv)) ? *psv : &PL_sv_no;
29122912
}
29132913
statement_pv = SvPV_nolen(statement_sv);
@@ -2918,7 +2918,7 @@ dbi_profile(SV *h, imp_xxh_t *imp_xxh, SV *statement_sv, SV *method, NV t1, NV t
29182918

29192919
dest_node = _profile_next_node(profile, "Data");
29202920

2921-
tmp = *hv_fetch((HV*)SvRV(profile), "Path", 4, 1);
2921+
tmp = *hv_fetchs((HV*)SvRV(profile), "Path", 1);
29222922
if (SvROK(tmp) && SvTYPE(SvRV(tmp))==SVt_PVAV) {
29232923
int len;
29242924
av = (AV*)SvRV(tmp);
@@ -3464,7 +3464,7 @@ XS(XS_DBI_dispatch)
34643464
if (is_DESTROY) {
34653465

34663466
/* force destruction of any outstanding children */
3467-
if ((tmp_svp = hv_fetch((HV*)SvRV(h), "ChildHandles", 12, FALSE)) && SvROK(*tmp_svp)) {
3467+
if ((tmp_svp = hv_fetchs((HV*)SvRV(h), "ChildHandles", FALSE)) && SvROK(*tmp_svp)) {
34683468
AV *av = (AV*)SvRV(*tmp_svp);
34693469
I32 kidslots;
34703470
PerlIO *logfp = DBILOGFP;
@@ -3556,7 +3556,7 @@ XS(XS_DBI_dispatch)
35563556
}
35573557

35583558
if (DBIc_has(imp_xxh,DBIcf_Callbacks)
3559-
&& (tmp_svp = hv_fetch((HV*)SvRV(h), "Callbacks", 9, 0))
3559+
&& (tmp_svp = hv_fetchs((HV*)SvRV(h), "Callbacks", 0))
35603560
&& ( (hook_svp = hv_fetch((HV*)SvRV(*tmp_svp), meth_name, strlen(meth_name), 0))
35613561
/* the "*" fallback callback only applies to non-nested calls
35623562
* and also doesn't apply to the 'set_err' or DESTROY methods.
@@ -3566,7 +3566,7 @@ XS(XS_DBI_dispatch)
35663566
*/
35673567
|| (!is_nested_call && !PL_dirty && meth_type != methtype_set_err &&
35683568
meth_type != methtype_DESTROY &&
3569-
(hook_svp = hv_fetch((HV*)SvRV(*tmp_svp), "*", 1, 0))
3569+
(hook_svp = hv_fetchs((HV*)SvRV(*tmp_svp), "*", 0))
35703570
)
35713571
)
35723572
&& SvROK(*hook_svp)
@@ -4003,7 +4003,7 @@ XS(XS_DBI_dispatch)
40034003
char intro[200];
40044004

40054005
if (meth_type == methtype_set_err) {
4006-
SV **sem_svp = hv_fetch((HV*)SvRV(h), "dbi_set_err_method", 18, GV_ADDWARN);
4006+
SV **sem_svp = hv_fetchs((HV*)SvRV(h), "dbi_set_err_method", GV_ADDWARN);
40074007
if (SvOK(*sem_svp))
40084008
err_meth_name = SvPV_nolen(*sem_svp);
40094009
}
@@ -4021,7 +4021,7 @@ XS(XS_DBI_dispatch)
40214021
if ( DBIc_has(imp_xxh, DBIcf_ShowErrorStatement)
40224022
&& !is_unrelated_to_Statement
40234023
&& (DBIc_TYPE(imp_xxh) == DBIt_ST || ima_flags & IMA_SHOW_ERR_STMT)
4024-
&& (statement_svp = hv_fetch((HV*)SvRV(h), "Statement", 9, 0))
4024+
&& (statement_svp = hv_fetchs((HV*)SvRV(h), "Statement", 0))
40254025
&& statement_svp && SvOK(*statement_svp)
40264026
) {
40274027
SV **svp = 0;
@@ -4031,7 +4031,7 @@ XS(XS_DBI_dispatch)
40314031
/* fetch from tied outer handle to trigger FETCH magic */
40324032
/* could add DBIcf_ShowErrorParams (default to on?) */
40334033
if (!(ima_flags & IMA_HIDE_ERR_PARAMVALUES)) {
4034-
svp = hv_fetch((HV*)DBIc_MY_H(imp_xxh),"ParamValues",11,FALSE);
4034+
svp = hv_fetchs((HV*)DBIc_MY_H(imp_xxh),"ParamValues",FALSE);
40354035
if (svp && SvMAGICAL(*svp))
40364036
mg_get(*svp); /* XXX may recurse, may croak. could use eval */
40374037
}
@@ -4056,7 +4056,7 @@ XS(XS_DBI_dispatch)
40564056
hook_svp = NULL;
40574057
if ( (SvTRUE(err_sv) || (is_warning && DBIc_has(imp_xxh, DBIcf_RaiseWarn)))
40584058
&& DBIc_has(imp_xxh, DBIcf_HandleError)
4059-
&& (hook_svp = hv_fetch((HV*)SvRV(h),"HandleError",11,0))
4059+
&& (hook_svp = hv_fetchs((HV*)SvRV(h),"HandleError",0))
40604060
&& hook_svp && SvOK(*hook_svp)
40614061
) {
40624062
dSP;
@@ -5126,7 +5126,7 @@ take_imp_data(h)
51265126
* destroyed they may need to interact with the 'zombie' parent dbh.
51275127
* So we do our best to neautralize them (finish & rebless)
51285128
*/
5129-
if ((tmp_svp = hv_fetch((HV*)SvRV(h), "ChildHandles", 12, FALSE)) && SvROK(*tmp_svp)) {
5129+
if ((tmp_svp = hv_fetchs((HV*)SvRV(h), "ChildHandles", FALSE)) && SvROK(*tmp_svp)) {
51305130
AV *av = (AV*)SvRV(*tmp_svp);
51315131
HV *zombie_stash = gv_stashpv("DBI::zombie", GV_ADDWARN);
51325132
I32 kidslots;
@@ -5570,7 +5570,7 @@ set_err(h, err, errstr=&PL_sv_no, state=&PL_sv_undef, method=&PL_sv_undef, resul
55705570
}
55715571
else {
55725572
/* store provided method name so handler code can find it */
5573-
sem_svp = hv_fetch((HV*)SvRV(h), "dbi_set_err_method", 18, 1);
5573+
sem_svp = hv_fetchs((HV*)SvRV(h), "dbi_set_err_method", 1);
55745574
if (SvOK(method)) {
55755575
sv_setpv(*sem_svp, SvPV_nolen(method));
55765576
}

Driver.xst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ DESTROY(dbh)
421421
&& (!PL_dirty || DBIc_DBISTATE(imp_dbh)->debug >= 3)
422422
) {
423423
warn("Issuing rollback() due to DESTROY without explicit disconnect() of %s handle %s",
424-
SvPV_nolen(*hv_fetch((HV*)SvRV(dbh), "ImplementorClass", 16, 1)),
425-
SvPV_nolen(*hv_fetch((HV*)SvRV(dbh), "Name", 4, 1))
424+
SvPV_nolen(*hv_fetchs((HV*)SvRV(dbh), "ImplementorClass", 1)),
425+
SvPV_nolen(*hv_fetchs((HV*)SvRV(dbh), "Name", 1))
426426
);
427427
}
428428
dbd_db_rollback(dbh, imp_dbh); /* ROLLBACK! */

Driver_xst.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ dbdxst_bind_params(SV *sth, imp_sth_t *imp_sth, I32 items, I32 ax)
6262
) {
6363
char errmsg[99];
6464
/* clear any previous ParamValues before error is generated */
65-
SV **svp = hv_fetch((HV*)DBIc_MY_H(imp_sth),"ParamValues",11,FALSE);
65+
SV **svp = hv_fetchs((HV*)DBIc_MY_H(imp_sth),"ParamValues",FALSE);
6666
if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) {
6767
HV *hv = (HV*)SvRV(*svp);
6868
hv_clear(hv);

0 commit comments

Comments
 (0)