diff options
author | Yves Orton <demerphq@gmail.com> | 2014-06-13 15:51:00 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2014-06-16 09:12:31 +0200 |
commit | 3d53a8ea562200eaacddbecddce21250ffed9eee (patch) | |
tree | 505882610575642b75ce13dcd8a1b6c77ff4b79c /ext/Hash-Util | |
parent | dc8b0d96b6966e02546ba8edb5b9bb9effd5b25e (diff) | |
download | perl-3d53a8ea562200eaacddbecddce21250ffed9eee.tar.gz |
Make hash_value() accept an optional seed
Diffstat (limited to 'ext/Hash-Util')
-rw-r--r-- | ext/Hash-Util/Util.xs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/ext/Hash-Util/Util.xs b/ext/Hash-Util/Util.xs index 3210200ae7..0687f7f4ce 100644 --- a/ext/Hash-Util/Util.xs +++ b/ext/Hash-Util/Util.xs @@ -70,17 +70,28 @@ hash_seed() void -hash_value(string) +hash_value(string,...) SV* string - PROTOTYPE: $ + PROTOTYPE: $;$ PPCODE: - STRLEN len; - char *pv; +{ UV uv; + STRLEN len; + char *pv= SvPV(string,len); + if (items<2) { + PERL_HASH(uv, pv, len); + } else { + STRLEN seedlen; + char *seedbuf= SvPV(ST(1),seedlen); + if ( seedlen < PERL_HASH_SEED_BYTES ) { + sv_dump(ST(1)); + Perl_croak(aTHX_ "seed len must be at least %d long only got %d bytes", PERL_HASH_SEED_BYTES, seedlen); + } - pv= SvPV(string,len); - PERL_HASH(uv,pv,len); + PERL_HASH_WITH_SEED(seedbuf, uv, pv, len); + } XSRETURN_UV(uv); +} void hash_traversal_mask(rhv, ...) |