summaryrefslogtreecommitdiff
path: root/embed.h
diff options
context:
space:
mode:
authorDavid Golden <dagolden@cpan.org>2010-09-09 17:22:02 -0400
committerDavid Golden <dagolden@cpan.org>2010-10-31 21:16:21 -0400
commitcba5a3b05660d6a40525beb667a389a690900298 (patch)
tree4cb5d682634ed416c8b77adb57765035314d1103 /embed.h
parentf64c9ac53bc4a5fa5967c92e98d7b42cca1ce97b (diff)
downloadperl-cba5a3b05660d6a40525beb667a389a690900298.tar.gz
Allow push/pop/keys/etc to act on references
All built-in functions that operate directly on array or hash containers now also accept hard references to arrays or hashes: |----------------------------+---------------------------| | Traditional syntax | Terse syntax | |----------------------------+---------------------------| | push @$arrayref, @stuff | push $arrayref, @stuff | | unshift @$arrayref, @stuff | unshift $arrayref, @stuff | | pop @$arrayref | pop $arrayref | | shift @$arrayref | shift $arrayref | | splice @$arrayref, 0, 2 | splice $arrayref, 0, 2 | | keys %$hashref | keys $hashref | | keys @$arrayref | keys $arrayref | | values %$hashref | values $hashref | | values @$arrayref | values $arrayref | | ($k,$v) = each %$hashref | ($k,$v) = each $hashref | | ($k,$v) = each @$arrayref | ($k,$v) = each $arrayref | |----------------------------+---------------------------| This allows these built-in functions to act on long dereferencing chains or on the return value of subroutines without needing to wrap them in C<@{}> or C<%{}>: push @{$obj->tags}, $new_tag; # old way push $obj->tags, $new_tag; # new way for ( keys %{$hoh->{genres}{artists}} ) {...} # old way for ( keys $hoh->{genres}{artists} ) {...} # new way For C<push>, C<unshift> and C<splice>, the reference will auto-vivify if it is not defined, just as if it were wrapped with C<@{}>. Calling C<keys> or C<values> directly on a reference gives a substantial performance improvement over explicit dereferencing. For C<keys>, C<values>, C<each>, when overloaded dereferencing is present, the overloaded dereference is used instead of dereferencing the underlying reftype. Warnings are issued about assumptions made in the following three ambiguous cases: (a) If both %{} and @{} overloading exists, %{} is used (b) If %{} overloading exists on a blessed arrayref, %{} is used (c) If @{} overloading exists on a blessed hashref, @{} is used
Diffstat (limited to 'embed.h')
-rw-r--r--embed.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/embed.h b/embed.h
index 134c349edb..31cd119f0c 100644
--- a/embed.h
+++ b/embed.h
@@ -938,6 +938,7 @@
#define ck_method(a) Perl_ck_method(aTHX_ a)
#define ck_null(a) Perl_ck_null(aTHX_ a)
#define ck_open(a) Perl_ck_open(aTHX_ a)
+#define ck_push(a) Perl_ck_push(aTHX_ a)
#define ck_readline(a) Perl_ck_readline(aTHX_ a)
#define ck_repeat(a) Perl_ck_repeat(aTHX_ a)
#define ck_require(a) Perl_ck_require(aTHX_ a)
@@ -1333,6 +1334,7 @@
#define pp_rand() Perl_pp_rand(aTHX)
#define pp_range() Perl_pp_range(aTHX)
#define pp_rcatline() Perl_pp_rcatline(aTHX)
+#define pp_reach() Perl_pp_reach(aTHX)
#define pp_read() Perl_pp_read(aTHX)
#define pp_readdir() Perl_pp_readdir(aTHX)
#define pp_readline() Perl_pp_readline(aTHX)
@@ -1353,12 +1355,14 @@
#define pp_rewinddir() Perl_pp_rewinddir(aTHX)
#define pp_right_shift() Perl_pp_right_shift(aTHX)
#define pp_rindex() Perl_pp_rindex(aTHX)
+#define pp_rkeys() Perl_pp_rkeys(aTHX)
#define pp_rmdir() Perl_pp_rmdir(aTHX)
#define pp_rv2av() Perl_pp_rv2av(aTHX)
#define pp_rv2cv() Perl_pp_rv2cv(aTHX)
#define pp_rv2gv() Perl_pp_rv2gv(aTHX)
#define pp_rv2hv() Perl_pp_rv2hv(aTHX)
#define pp_rv2sv() Perl_pp_rv2sv(aTHX)
+#define pp_rvalues() Perl_pp_rvalues(aTHX)
#define pp_sassign() Perl_pp_sassign(aTHX)
#define pp_say() Perl_pp_say(aTHX)
#define pp_scalar() Perl_pp_scalar(aTHX)