summaryrefslogtreecommitdiff
path: root/hv.c
diff options
context:
space:
mode:
Diffstat (limited to 'hv.c')
-rw-r--r--hv.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/hv.c b/hv.c
index 6d6c3ce2a1..3966b1f991 100644
--- a/hv.c
+++ b/hv.c
@@ -834,6 +834,45 @@ newHV(void)
return hv;
}
+HV *
+newHVhv(HV *ohv)
+{
+ register HV *hv;
+ register XPVHV* xhv;
+ STRLEN hv_max = ohv ? HvMAX(ohv) : 0;
+ STRLEN hv_fill = ohv ? HvFILL(ohv) : 0;
+
+ hv = newHV();
+ while (hv_max && hv_max + 1 >= hv_fill * 2)
+ hv_max = hv_max / 2; /* Is always 2^n-1 */
+ ((XPVHV*)SvANY(hv))->xhv_max = hv_max;
+ if (!hv_fill)
+ return hv;
+
+#if 0
+ if (!SvRMAGICAL(ohv) || !mg_find((SV*)ohv,'P')) {
+ /* Quick way ???*/
+ }
+ else
+#endif
+ {
+ HE *entry;
+ I32 hv_riter = HvRITER(ohv); /* current root of iterator */
+ HE *hv_eiter = HvEITER(ohv); /* current entry of iterator */
+
+ /* Slow way */
+ hv_iterinit(hv);
+ while (entry = hv_iternext(ohv)) {
+ hv_store(hv, HeKEY(entry), HeKLEN(entry),
+ SvREFCNT_inc(HeVAL(entry)), HeHASH(entry));
+ }
+ HvRITER(ohv) = hv_riter;
+ HvEITER(ohv) = hv_eiter;
+ }
+
+ return hv;
+}
+
void
hv_free_ent(HV *hv, register HE *entry)
{