Skip to content

Commit

Permalink
Move the call to hv_iterval() out of store_hentry().
Browse files Browse the repository at this point in the history
Previously the regular hash store code had been calling hv_iterval() twice
for each hash entry. This probably isn't going to generate incorrect results,
but is inefficient. This performance regression was added as part of commit
1cb8a34:
    Storable 3.00: u64 strings, arrays and hashes >2G
  • Loading branch information
nwc10 committed Aug 30, 2021
1 parent f934338 commit 28fa706
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions dist/Storable/Storable.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,8 @@ static SV *get_larray(pTHX_ stcxt_t *cxt, UV len, const char *cname);
static SV *get_lhash(pTHX_ stcxt_t *cxt, UV len, int hash_flags, const char *cname);
static int store_lhash(pTHX_ stcxt_t *cxt, HV *hv, unsigned char hash_flags);
#endif
static int store_hentry(pTHX_ stcxt_t *cxt, HV* hv, UV i, HE *he, unsigned char hash_flags);
static int store_hentry(pTHX_ stcxt_t *cxt, HV* hv, UV i, HE *he, SV *val,
unsigned char hash_flags);

typedef SV* (*sv_retrieve_t)(pTHX_ stcxt_t *cxt, const char *name);

Expand Down Expand Up @@ -3015,7 +3016,7 @@ static int store_hash(pTHX_ stcxt_t *cxt, HV *hv)
if (val == 0)
return 1; /* Internal error, not I/O error */

if ((ret = store_hentry(aTHX_ cxt, hv, i, he, hash_flags)))
if ((ret = store_hentry(aTHX_ cxt, hv, i, he, val, hash_flags)))
goto out;
}
}
Expand All @@ -3035,10 +3036,9 @@ static int store_hash(pTHX_ stcxt_t *cxt, HV *hv)
}

static int store_hentry(pTHX_
stcxt_t *cxt, HV* hv, UV i, HE *he, unsigned char hash_flags)
stcxt_t *cxt, HV* hv, UV i, HE *he, SV *val, unsigned char hash_flags)
{
int ret = 0;
SV* val = hv_iterval(hv, he);
int flagged_hash = ((SvREADONLY(hv)
#ifdef HAS_HASH_KEY_FLAGS
|| HvHASKFLAGS(hv)
Expand Down Expand Up @@ -3172,7 +3172,8 @@ static int store_lhash(pTHX_ stcxt_t *cxt, HV *hv, unsigned char hash_flags)
HE* entry = array[i];

while (entry) {
if ((ret = store_hentry(aTHX_ cxt, hv, ix++, entry, hash_flags)))
SV* val = hv_iterval(hv, entry);
if ((ret = store_hentry(aTHX_ cxt, hv, ix++, entry, val, hash_flags)))
return ret;
entry = HeNEXT(entry);
}
Expand Down

0 comments on commit 28fa706

Please sign in to comment.