]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blobdiff - lib/Scalar/Vec/Util.pm
Speed up vfill_pp()
[perl/modules/Scalar-Vec-Util.git] / lib / Scalar / Vec / Util.pm
index c80d6424c1c4dc920c4b9729053a7fd271b00a81..12d049c26364708fa28e59b337745040da53e5e4 100644 (file)
@@ -81,8 +81,17 @@ sub vfill_pp {
  (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 >>