Skip to content

Commit

Permalink
- Fixed the Hash.flip() method
Browse files Browse the repository at this point in the history
- Modified the Array.copy() and Hash.copy() methods to use Storable::dclone(), which is much faster and safer than recreating the objects.
- Added the alias Sys.clone() for Sys.copy()
  • Loading branch information
trizen committed Sep 8, 2015
1 parent 72ca7d9 commit 86d9350
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/Sidef/Sys/Sys.pm
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ package Sidef::Sys::Sys {
Storable::dclone($obj);
}

*clone = \©

sub select {
my ($self, $fh) = @_;
CORE::select(CORE::ref($fh) eq 'GLOB' ? $fh : $fh->get_value);
Expand Down
8 changes: 3 additions & 5 deletions lib/Sidef/Types/Array/Array.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1190,11 +1190,9 @@ package Sidef::Types::Array::Array {
sub copy {
my ($self) = @_;
my $new = $self->new;
foreach my $item (map { $_->get_value } @{$self}) {
$new->append(eval { $item->can('copy') } ? $item->copy : $item);
}
$new;
state $x = require Storable;
Storable::dclone($self);
}
sub delete_first {
Expand Down
10 changes: 7 additions & 3 deletions lib/Sidef/Types/Hash/Hash.pm
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,18 @@ package Sidef::Types::Hash::Hash {
my ($self) = @_;

my $new_hash = $self->new();
@{$new_hash}{CORE::values %{$self->{data}}} =
(map { Sidef::Types::String::String->new($_) } CORE::keys %{$self->{data}});
@{$new_hash->{data}}{map { $_->get_value } CORE::values %{$self->{data}}} =
(map { Sidef::Variable::Variable->new(name => '', type => 'var', value => Sidef::Types::String::String->new($_)) }
CORE::keys %{$self->{data}});

$new_hash;
}

sub copy {
my ($self) = @_;
$self->new(map { ref($_) ? $_->get_value : $_ } %{$self->{data}});

state $x = require Storable;
Storable::dclone($self);
}

sub dump {
Expand Down

0 comments on commit 86d9350

Please sign in to comment.