summaryrefslogtreecommitdiff
path: root/dump.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2010-11-25 11:53:10 +0000
committerNicholas Clark <nick@ccl4.org>2010-11-25 11:53:10 +0000
commitec3405c82bf3efe09e36ca55c492c32c1235f449 (patch)
treeaab36b0d51e4d6da1a931e06f2c2fa2af483b47d /dump.c
parentbed530647b88d70e1ad8d2e42b54447ea27c5bd3 (diff)
downloadperl-ec3405c82bf3efe09e36ca55c492c32c1235f449.tar.gz
Refactor ENAME dumping in Perl_do_sv_dump() to simplify the code slightly.
Simpler code avoids the need for a comment explaining how the complex code was working. Also use newSVpvs_flags() in place of sv_newmortal() and sv_setpv().
Diffstat (limited to 'dump.c')
-rw-r--r--dump.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/dump.c b/dump.c
index 4bda943bff..d778d41c9e 100644
--- a/dump.c
+++ b/dump.c
@@ -1863,29 +1863,26 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
(IV)HvAUX(sv)->xhv_name_count
);
if (HvAUX(sv)->xhv_name_u.xhvnameu_name && HvENAME_HEK_NN(sv)) {
- if (HvAUX(sv)->xhv_name_count) {
- SV * const names = sv_newmortal();
- HEK ** const namep = HvAUX(sv)->xhv_name_u.xhvnameu_names;
- const I32 count = HvAUX(sv)->xhv_name_count;
- /* This line sets hekp to one element before the first
- name, so the ++hekp below will put us at the start-
- ing point.
- That starting point is the first element if count
- is positive and the second element if count
- is negative.
- */
- HEK **hekp = namep - (count > 0);
- sv_setpv(names, "");
- while (++hekp < namep + (count < 0 ? -count : count))
+ const I32 count = HvAUX(sv)->xhv_name_count;
+ if (count) {
+ SV * const names = newSVpvs_flags("", SVs_TEMP);
+ /* The starting point is the first element if count is
+ positive and the second element if count is negative. */
+ HEK *const *hekp = HvAUX(sv)->xhv_name_u.xhvnameu_names
+ + (count < 0 ? 1 : 0);
+ HEK *const *const endp = HvAUX(sv)->xhv_name_u.xhvnameu_names
+ + (count < 0 ? -count : count);
+ while (hekp < endp) {
if (*hekp) {
sv_catpvs(names, ", \"");
- sv_catpvn(
- names, HEK_KEY(*hekp), HEK_LEN(*hekp)
- );
+ sv_catpvn(names, HEK_KEY(*hekp), HEK_LEN(*hekp));
sv_catpvs(names, "\"");
+ } else {
+ /* This should never happen. */
+ sv_catpvs(names, ", (null)");
}
- /* This should never happen. */
- else sv_catpvs(names, ", (null)");
+ ++hekp;
+ }
Perl_dump_indent(aTHX_
level, file, " ENAME = %s\n", SvPV_nolen(names)+2
);