- t = svu_prepare_sv(st, ts, l);
-
- f = SvPVX(sf); /* We do it there in case st == sf. */
- c = SvCUR(sf);
- if (c * CHAR_BIT <= fs + l && c <= SvCUR(st)) {
- lf = fs + l - c * CHAR_BIT;
- l = c * CHAR_BIT - fs;
+ SvUPGRADE(sf, SVt_PV);
+ vt = svu_prepare_sv(st, ts, l);
+
+ /* We fetch vf after upgrading st in case st == sf. */
+ vf = SvPVX(sf);
+ cf = SvCUR(sf) * CHAR_BIT;
+ lf = fs + l;
+ e = lf > cf ? lf - cf : 0;
+ l = l > e ? l - e : 0;
+
+ if (l) {
+ if (vf == vt)
+ bv_move(vf, ts, fs, l);
+ else
+ bv_copy(vt, ts, vf, fs, l);