Commit 893e3c5
committed
Core: Avoid reading outside of collection bounds
Consider the following collection:
const array = ['a', 'b', 'c'];
Retrieving `array[0]` can be done relatively quickly. However, when the property
doesn’t exist on the receiver, JavaScript engines must continue to look up the
prototype chain until either the property is found or the chain ends. This is
inherently slower than *not* doing any prototype chain lookups. Retrieving an
out-of-bounds index, e.g. `array[3]`, triggers this scenario, resulting in
decreased performance.
This patch changes the way some loops are written to avoid running into the slow
case unnecessarily.1 parent f6bd902 commit 893e3c5
File tree
5 files changed
+41
-33
lines changed- dist
- src
5 files changed
+41
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
661 | | - | |
| 661 | + | |
662 | 662 | | |
663 | 663 | | |
664 | 664 | | |
| |||
671 | 671 | | |
672 | 672 | | |
673 | 673 | | |
| 674 | + | |
674 | 675 | | |
675 | | - | |
| 676 | + | |
676 | 677 | | |
677 | 678 | | |
678 | 679 | | |
| |||
702 | 703 | | |
703 | 704 | | |
704 | 705 | | |
705 | | - | |
| 706 | + | |
| 707 | + | |
706 | 708 | | |
707 | 709 | | |
708 | 710 | | |
709 | | - | |
| 711 | + | |
710 | 712 | | |
711 | 713 | | |
712 | 714 | | |
| |||
1054 | 1056 | | |
1055 | 1057 | | |
1056 | 1058 | | |
1057 | | - | |
| 1059 | + | |
| 1060 | + | |
1058 | 1061 | | |
1059 | 1062 | | |
1060 | 1063 | | |
1061 | 1064 | | |
1062 | 1065 | | |
1063 | 1066 | | |
1064 | 1067 | | |
1065 | | - | |
1066 | | - | |
1067 | | - | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
1068 | 1072 | | |
1069 | 1073 | | |
1070 | 1074 | | |
| |||
0 commit comments