@@ -139,17 +139,6 @@ static collections_deque *collections_deque_from_object(zend_object *obj)
139
139
140
140
#define Z_DEQUE_P (zv ) collections_deque_from_object(Z_OBJ_P((zv)))
141
141
142
- /* Helps enforce the invariants in debug mode:
143
- * - if size == 0, then circular_buffer == NULL
144
- * - if size > 0, then circular_buffer != NULL
145
- * - size is not less than 0
146
- */
147
- static bool collections_deque_entries_empty_size (const collections_deque_entries * array )
148
- {
149
- DEBUG_ASSERT_CONSISTENT_DEQUE (array );
150
- return array -> size == 0 ;
151
- }
152
-
153
142
static bool collections_deque_entries_empty_capacity (const collections_deque_entries * array )
154
143
{
155
144
DEBUG_ASSERT_CONSISTENT_DEQUE (array );
@@ -760,6 +749,7 @@ static zend_array* collections_deque_to_new_array(const collections_deque_entrie
760
749
do {
761
750
Z_TRY_ADDREF_P (p );
762
751
ZEND_HASH_FILL_ADD (p );
752
+ p ++ ;
763
753
if (p == end ) {
764
754
p = circular_buffer ;
765
755
}
@@ -769,20 +759,6 @@ static zend_array* collections_deque_to_new_array(const collections_deque_entrie
769
759
return values ;
770
760
}
771
761
772
- PHP_METHOD (Collections_Deque , __serialize )
773
- {
774
- ZEND_PARSE_PARAMETERS_NONE ();
775
-
776
- collections_deque * intern = Z_DEQUE_P (ZEND_THIS );
777
-
778
- if (collections_deque_entries_empty_size (& intern -> array )) {
779
- RETURN_EMPTY_ARRAY ();
780
- }
781
- /* Unlike FixedArray, there's no setSize, so there's no reason to delete indexes */
782
-
783
- RETURN_ARR (collections_deque_to_new_array (& intern -> array ));
784
- }
785
-
786
762
PHP_METHOD (Collections_Deque , toArray )
787
763
{
788
764
ZEND_PARSE_PARAMETERS_NONE ();
@@ -1087,14 +1063,14 @@ PHP_METHOD(Collections_Deque, pop)
1087
1063
collections_deque_try_shrink_capacity (intern , old_size );
1088
1064
}
1089
1065
1090
- PHP_METHOD (Collections_Deque , top )
1066
+ PHP_METHOD (Collections_Deque , last )
1091
1067
{
1092
1068
ZEND_PARSE_PARAMETERS_NONE ();
1093
1069
1094
1070
const collections_deque * intern = Z_DEQUE_P (ZEND_THIS );
1095
1071
const size_t old_size = intern -> array .size ;
1096
1072
if (old_size == 0 ) {
1097
- zend_throw_exception (spl_ce_UnderflowException , "Cannot read top of empty Collections\\Deque" , 0 );
1073
+ zend_throw_exception (spl_ce_UnderflowException , "Cannot read last value of empty Collections\\Deque" , 0 );
1098
1074
RETURN_THROWS ();
1099
1075
}
1100
1076
@@ -1126,14 +1102,14 @@ PHP_METHOD(Collections_Deque, shift)
1126
1102
collections_deque_try_shrink_capacity (intern , old_size );
1127
1103
}
1128
1104
1129
- PHP_METHOD (Collections_Deque , bottom )
1105
+ PHP_METHOD (Collections_Deque , first )
1130
1106
{
1131
1107
ZEND_PARSE_PARAMETERS_NONE ();
1132
1108
1133
1109
const collections_deque * intern = Z_DEQUE_P (ZEND_THIS );
1134
1110
DEBUG_ASSERT_CONSISTENT_DEQUE (& intern -> array );
1135
1111
if (intern -> array .size == 0 ) {
1136
- zend_throw_exception (spl_ce_UnderflowException , "Cannot read bottom of empty Collections\\Deque" , 0 );
1112
+ zend_throw_exception (spl_ce_UnderflowException , "Cannot read first value of empty Collections\\Deque" , 0 );
1137
1113
RETURN_THROWS ();
1138
1114
}
1139
1115
@@ -1152,45 +1128,6 @@ PHP_METHOD(Collections_Deque, offsetUnset)
1152
1128
RETURN_THROWS ();
1153
1129
}
1154
1130
1155
- static void collections_deque_return_list (zval * return_value , const collections_deque * intern )
1156
- {
1157
- // Can't use collections_convert_zval_list_to_php_array_list(return_value, intern->array.circular_buffer, intern->array.size) for deque.
1158
- const size_t len = intern -> array .size ;
1159
- if (!len ) {
1160
- RETURN_EMPTY_ARRAY ();
1161
- }
1162
- ZEND_ASSERT (intern -> array .mask > 0 );
1163
-
1164
- zend_array * values = zend_new_array (len );
1165
- /* Initialize return array */
1166
- zend_hash_real_init_packed (values );
1167
-
1168
- zval * const from_buffer_start = intern -> array .circular_buffer ;
1169
- zval * from_begin = & from_buffer_start [intern -> array .offset ];
1170
- zval * const from_end = & from_buffer_start [intern -> array .mask + 1 ];
1171
- ZEND_ASSERT (from_begin <= from_end );
1172
- /* Go through values and add values to the return array */
1173
- ZEND_HASH_FILL_PACKED (values ) {
1174
- for (size_t i = 0 ; i < len ; i ++ ) {
1175
- if (from_begin == from_end ) {
1176
- from_begin = from_buffer_start ;
1177
- }
1178
- Z_TRY_ADDREF_P (from_begin );
1179
- ZEND_HASH_FILL_ADD (from_begin );
1180
- from_begin ++ ;
1181
- }
1182
- } ZEND_HASH_FILL_END ();
1183
- RETURN_ARR (values );
1184
- }
1185
-
1186
- PHP_METHOD (Collections_Deque , jsonSerialize )
1187
- {
1188
- /* json_encoder.c will always encode objects as {"0":..., "1":...}, and detects recursion if an object returns its internal property array, so we have to return a new array */
1189
- ZEND_PARSE_PARAMETERS_NONE ();
1190
- collections_deque * intern = Z_DEQUE_P (ZEND_THIS );
1191
- collections_deque_return_list (return_value , intern );
1192
- }
1193
-
1194
1131
PHP_MINIT_FUNCTION (collections_deque )
1195
1132
{
1196
1133
collections_ce_Deque = register_class_Collections_Deque (zend_ce_aggregate , zend_ce_countable , php_json_serializable_ce , zend_ce_arrayaccess );
0 commit comments