Commit f57b916
committed
Add support for empty immutable shared arrays
Why:
- Since PHP 7.3, it's possible for extensions to create zvals backed by
an immutable shared hashtable via the ZVAL_EMPTY_ARRAY macro.
- This helps avoid redundant hashtable allocations when returning empty arrays
back to userland PHP code, and could likewise be beneficial for Rust extensions too.
What:
- Add ZendHashTable::new_empty_immutable() to obtain a ZendHashTable
that is actually an empty immutable shared hashtable.
- Add ZendHashTable::is_immutable(). Use it to avoid attempting to
free the immutable shared hashtable on drop, and to set appropriate
type flags when initializing a zval with a ZendHashTable.
- Make ZendHashTable's TryFrom implementations from Vec and HashMap return
an empty immutable shared hashtable if the input collection was empty.
Although this would allow every user to automatically benefit from
this optimization, I'm not convinced about this part because this is technically a
breaking change for consumers that construct ZendHashTables via these
converters in their Rust code. Maybe it'd be better to not change the
converters and let projects explicitly use ::new_empty_immutable if they
deem the optimization would be useful.1 parent 464407b commit f57b916
File tree
7 files changed
+205
-64
lines changed- src
- types
- tests/src
- integration
7 files changed
+205
-64
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
| |||
269 | 273 | | |
270 | 274 | | |
271 | 275 | | |
272 | | - | |
| 276 | + | |
273 | 277 | | |
274 | 278 | | |
275 | 279 | | |
| |||
537 | 541 | | |
538 | 542 | | |
539 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
540 | 547 | | |
541 | 548 | | |
542 | 549 | | |
| |||
1992 | 1999 | | |
1993 | 2000 | | |
1994 | 2001 | | |
1995 | | - | |
| 2002 | + | |
1996 | 2003 | | |
1997 | 2004 | | |
1998 | 2005 | | |
| |||
2011 | 2018 | | |
2012 | 2019 | | |
2013 | 2020 | | |
2014 | | - | |
2015 | | - | |
| 2021 | + | |
| 2022 | + | |
2016 | 2023 | | |
2017 | 2024 | | |
2018 | | - | |
| 2025 | + | |
2019 | 2026 | | |
2020 | | - | |
| 2027 | + | |
2021 | 2028 | | |
2022 | 2029 | | |
2023 | 2030 | | |
2024 | 2031 | | |
2025 | | - | |
2026 | | - | |
| 2032 | + | |
| 2033 | + | |
2027 | 2034 | | |
2028 | 2035 | | |
2029 | | - | |
| 2036 | + | |
2030 | 2037 | | |
2031 | | - | |
| 2038 | + | |
2032 | 2039 | | |
2033 | 2040 | | |
2034 | 2041 | | |
2035 | 2042 | | |
2036 | | - | |
2037 | | - | |
| 2043 | + | |
| 2044 | + | |
2038 | 2045 | | |
2039 | 2046 | | |
2040 | | - | |
| 2047 | + | |
2041 | 2048 | | |
2042 | | - | |
| 2049 | + | |
2043 | 2050 | | |
2044 | 2051 | | |
2045 | 2052 | | |
2046 | 2053 | | |
2047 | | - | |
2048 | | - | |
| 2054 | + | |
| 2055 | + | |
2049 | 2056 | | |
2050 | 2057 | | |
2051 | | - | |
| 2058 | + | |
2052 | 2059 | | |
2053 | | - | |
| 2060 | + | |
2054 | 2061 | | |
2055 | 2062 | | |
2056 | 2063 | | |
2057 | 2064 | | |
2058 | | - | |
2059 | | - | |
| 2065 | + | |
| 2066 | + | |
2060 | 2067 | | |
2061 | 2068 | | |
2062 | | - | |
| 2069 | + | |
2063 | 2070 | | |
2064 | | - | |
| 2071 | + | |
2065 | 2072 | | |
2066 | 2073 | | |
2067 | 2074 | | |
2068 | 2075 | | |
2069 | | - | |
2070 | | - | |
| 2076 | + | |
| 2077 | + | |
2071 | 2078 | | |
2072 | 2079 | | |
2073 | | - | |
| 2080 | + | |
2074 | 2081 | | |
2075 | | - | |
| 2082 | + | |
2076 | 2083 | | |
2077 | 2084 | | |
2078 | 2085 | | |
2079 | 2086 | | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
2080 | 2098 | | |
2081 | | - | |
2082 | | - | |
2083 | | - | |
2084 | | - | |
2085 | | - | |
2086 | | - | |
2087 | | - | |
2088 | | - | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
2089 | 2108 | | |
2090 | | - | |
| 2109 | + | |
2091 | 2110 | | |
2092 | 2111 | | |
2093 | 2112 | | |
2094 | | - | |
| 2113 | + | |
2095 | 2114 | | |
2096 | 2115 | | |
2097 | 2116 | | |
2098 | | - | |
| 2117 | + | |
2099 | 2118 | | |
2100 | 2119 | | |
2101 | 2120 | | |
2102 | | - | |
| 2121 | + | |
2103 | 2122 | | |
2104 | 2123 | | |
2105 | 2124 | | |
2106 | | - | |
| 2125 | + | |
2107 | 2126 | | |
2108 | 2127 | | |
2109 | 2128 | | |
2110 | | - | |
| 2129 | + | |
2111 | 2130 | | |
2112 | 2131 | | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
2113 | 2137 | | |
2114 | 2138 | | |
2115 | 2139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
74 | 95 | | |
75 | 96 | | |
76 | 97 | | |
| |||
102 | 123 | | |
103 | 124 | | |
104 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
105 | 147 | | |
106 | 148 | | |
107 | 149 | | |
| |||
539 | 581 | | |
540 | 582 | | |
541 | 583 | | |
542 | | - | |
543 | | - | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
544 | 588 | | |
545 | 589 | | |
546 | 590 | | |
| |||
878 | 922 | | |
879 | 923 | | |
880 | 924 | | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
881 | 929 | | |
882 | 930 | | |
883 | 931 | | |
| |||
943 | 991 | | |
944 | 992 | | |
945 | 993 | | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
946 | 998 | | |
947 | 999 | | |
948 | 1000 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
566 | | - | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
567 | 574 | | |
568 | 575 | | |
569 | 576 | | |
| |||
0 commit comments