(undef, my $s, my $l, my $x) = @_;
croak "Invalid argument" unless _alldef @_;
return unless $l;
- $x = 1 if $x;
- vec($_[0], $_, 1) = $x for $s .. $s + $l - 1;
+ $x = ~0 if $x;
+ my $SIZE = 32;
+ my $t = int($s / $SIZE) + 1;
+ my $u = int(($s + $l) / $SIZE);
+ if ($SIZE * $t < $s + $l and $t <= $u) {
+ vec($_[0], $_, 1) = $x for $s .. $SIZE * $t - 1;
+ vec($_[0], $_, $SIZE) = $x for $t .. $u - 1;
+ vec($_[0], $_, 1) = $x for $SIZE * $u .. $s + $l - 1;
+ } else {
+ vec($_[0], $_, 1) = $x for $s .. $s + $l - 1;
+ }
}
=head2 C<< vcopy $from => $from_start, $to => $to_start, $length >>
use Test::More 'no_plan';
-use Scalar::Vec::Util qw/SVU_SIZE/;
+use Scalar::Vec::Util;
eval { Scalar::Vec::Util::veq_pp(undef, 0, my $y, 0, 0) };
like($@, qr/Invalid\s+argument/, 'first argument undef croaks');
eval { Scalar::Vec::Util::veq_pp(my $x, 0, my $y, 0, undef) };
like($@, qr/Invalid\s+argument/, 'fifth argument undef croaks');
-my $p = SVU_SIZE;
-$p = 8 if $p < 8;
+my $p = 8;
my $n = 3 * $p;
my $q = 1;
-*myfill = *Scalar::Vec::Util::vfill_pp;
+sub myfill {
+ (undef, my $s, my $l, my $x) = @_;
+ $x = 1 if $x;
+ vec($_[0], $_, 1) = $x for $s .. $s + $l - 1;
+}
sub rst { myfill($_[0], 0, $n, 0) }
my $n = 3 * $p;
my $q = 1;
-*myfill = *Scalar::Vec::Util::vfill_pp;
+sub myfill {
+ (undef, my $s, my $l, my $x) = @_;
+ $x = 1 if $x;
+ vec($_[0], $_, 1) = $x for $s .. $s + $l - 1;
+}
sub rst { myfill($_[0], 0, $n, 0) }
like($@, qr/Invalid\s+argument/, 'third argument undef croaks');
eval { Scalar::Vec::Util::vfill_pp(my $x, 0, 0, undef) };
like($@, qr/Invalid\s+argument/, 'fourth argument undef croaks');
+
+my $p = 8;
+my $n = 3 * $p;
+my $q = 1;
+
+sub myfill {
+ (undef, my $s, my $l, my $x) = @_;
+ $x = 1 if $x;
+ vec($_[0], $_, 1) = $x for $s .. $s + $l - 1;
+}
+
+*myeq = *Scalar::Vec::Util::veq_pp;
+
+sub rst { myfill($_[0], 0, $n, 0); $_[0] = '' }
+
+my ($v, $c) = ('') x 2;
+
+my @s = ($p - $q) .. ($p + $q);
+for my $s (@s) {
+ for my $l (0 .. $n - 1) {
+ next if $s + $l > $n;
+ rst $c;
+ myfill($c, 0, $s, 0);
+ myfill($c, $s, $l, 1);
+ rst $v;
+ Scalar::Vec::Util::vfill_pp($v, 0, $s, 0);
+ Scalar::Vec::Util::vfill_pp($v, $s, $l, 1);
+ ok(myeq($v, 0, $c, 0, $n), "vfill_pp $s, $l");
+ is(length $v, length $c, "vfill_pp $s, $l length");
+ }
+}