Commit de92f7e
committed
Perl_newSLICEOP: Optimise '(caller)[0]' into 'scalar caller'
A subroutine can obtain just the package of its caller in a couple of ways.
Both seem somewhat common.
* `caller` - in scaler context, as in `my $x = caller;`
* `(caller)[0]`, as in `my $x = (caller)[0];`
In the first, `caller` finds the package name, sticks it in a new SV, and
puts that (or `undef`) on the stack:
<0> caller[t2] s
In the second, `caller` (a) finds the package name, filename, and line
(b) creates three new SVs to hold them all (c) puts those SVs on the stack
(d) does a list slice to leave just the package SV on the stack.
7 <2> lslice sK/2 ->8
- <1> ex-list lK ->5
3 <0> pushmark s ->4
4 <$> const[IV 0] s ->5
- <1> ex-list lK ->7
5 <0> pushmark s ->6
6 <0> caller[t2] l ->7
This commit checks for the second case inside `Perl_newSLICEOP` and
instead of constructing a `lslice` OP, returns just the `caller` OP
with scalar context applied.1 parent d6f09a8 commit de92f7e
5 files changed
+38
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
2586 | 2586 | | |
2587 | 2587 | | |
2588 | 2588 | | |
2589 | | - | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
2590 | 2597 | | |
2591 | 2598 | | |
2592 | 2599 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8534 | 8534 | | |
8535 | 8535 | | |
8536 | 8536 | | |
| 8537 | + | |
| 8538 | + | |
| 8539 | + | |
| 8540 | + | |
| 8541 | + | |
| 8542 | + | |
| 8543 | + | |
| 8544 | + | |
| 8545 | + | |
| 8546 | + | |
| 8547 | + | |
8537 | 8548 | | |
8538 | 8549 | | |
8539 | 8550 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
| 168 | + | |
167 | 169 | | |
168 | 170 | | |
169 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1106 | 1106 | | |
1107 | 1107 | | |
1108 | 1108 | | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
1109 | 1118 | | |
0 commit comments