RT# 50541: Fix for clear bug. Introduces a speed regression
[dbsrgits/DBM-Deep.git] / lib / DBM / Deep / Array.pm
index b4a4636..247d730 100644 (file)
@@ -5,6 +5,8 @@ use 5.006_000;
 use strict;
 use warnings FATAL => 'all';
 
+our $VERSION = $DBM::Deep::VERSION;
+
 # This is to allow DBM::Deep::Array to handle negative indices on
 # its own. Otherwise, Perl would intercept the call to negative
 # indices for us. This was causing bugs for negative index handling.
@@ -392,6 +394,18 @@ sub _copy_node {
     return 1;
 }
 
+sub _clear {
+    my $self = shift;
+
+    my $size = $self->FETCHSIZE;
+    for my $key ( 0 .. $size - 1 ) {
+        $self->_engine->delete_key( $self, $key, $key );
+    }
+    $self->STORESIZE( 0 );
+
+    return;
+}
+
 sub length  { (shift)->FETCHSIZE(@_) }
 sub pop     { (shift)->POP(@_)       }
 sub push    { (shift)->PUSH(@_)      }