- Notifications
You must be signed in to change notification settings - Fork587
Commitd6f958e
committed
OP_SUBSTR_NIBBLE - a specialised OP_SUBSTR variant
This commit adds OP_SUBSTR_NIBBLE and associated machinery for fasthandling of the constructions: substr EXPR,0,LENGTH,''and substr EXPR,0,LENGTHWhere EXPR is a scalar lexical, the OFFSET is zero, and either thereis no REPLACEMENT or it is the empty string. LENGTH can be anythingthat OP_SUBSTR supports. These constraints allow for a very strippedback and optimised version of pp_substr.The primary motivation was for situations where a scalar, containingsome network packets or other binary data structure, is being parsedpiecemeal. Nibbling away at the scalar can be useful when you don'tknow how exactly it will be parsed and unpacked until you get started.It also means that you don't need to worry about correctly updatinga separate offset variable.This operator also turns out to be an efficient way to (destructively)break an expression up into fixed size chunks. For example, given: my $x = ''; my $str = "A"x100_000_000;This code: $x = substr($str, 0, 5, "") while ($str);is twice as fast as doing: for ($pos = 0; $pos < length($str); $pos += 5) { $x = substr($str, $pos, 5); }Compared with blead, `$y = substr($x, 0, 5)` runs 40% faster and`$y = substr($x, 0, 5, '')` runs 45% faster.1 parentff0ce7d commitd6f958e
File tree
15 files changed
+793
-395
lines changed- ext/Opcode
- lib/B
- regen
- t
- op
- perf
15 files changed
+793
-395
lines changedLines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6436 | 6436 |
| |
6437 | 6437 |
| |
6438 | 6438 |
| |
| 6439 | + | |
6439 | 6440 |
| |
6440 | 6441 |
| |
6441 | 6442 |
| |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 |
| - | |
| 1 | + | |
2 | 2 |
| |
3 | 3 |
| |
4 | 4 |
| |
| |||
322 | 322 |
| |
323 | 323 |
| |
324 | 324 |
| |
325 |
| - | |
| 325 | + | |
| 326 | + | |
326 | 327 |
| |
327 | 328 |
| |
328 | 329 |
| |
|
Lines changed: 20 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
7 | 7 |
| |
8 | 8 |
| |
9 | 9 |
| |
10 |
| - | |
| 10 | + | |
11 | 11 |
| |
12 | 12 |
| |
13 | 13 |
| |
| |||
3419 | 3419 |
| |
3420 | 3420 |
| |
3421 | 3421 |
| |
| 3422 | + | |
| 3423 | + | |
| 3424 | + | |
| 3425 | + | |
| 3426 | + | |
| 3427 | + | |
| 3428 | + | |
| 3429 | + | |
| 3430 | + | |
| 3431 | + | |
| 3432 | + | |
| 3433 | + | |
| 3434 | + | |
| 3435 | + | |
| 3436 | + | |
| 3437 | + | |
| 3438 | + | |
| 3439 | + | |
| 3440 | + | |
3422 | 3441 |
| |
3423 | 3442 |
| |
3424 | 3443 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1757 | 1757 |
| |
1758 | 1758 |
| |
1759 | 1759 |
| |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
1760 | 1768 |
| |
1761 | 1769 |
| |
1762 | 1770 |
| |
|
Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
0 commit comments
Comments
(0)