@@ -139,17 +139,6 @@ static collections_deque *collections_deque_from_object(zend_object *obj)
139139
140140#define Z_DEQUE_P (zv ) collections_deque_from_object(Z_OBJ_P((zv)))
141141
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-
153142static bool collections_deque_entries_empty_capacity (const collections_deque_entries * array )
154143{
155144 DEBUG_ASSERT_CONSISTENT_DEQUE (array );
@@ -760,6 +749,7 @@ static zend_array* collections_deque_to_new_array(const collections_deque_entrie
760749 do {
761750 Z_TRY_ADDREF_P (p );
762751 ZEND_HASH_FILL_ADD (p );
752+ p ++ ;
763753 if (p == end ) {
764754 p = circular_buffer ;
765755 }
@@ -769,20 +759,6 @@ static zend_array* collections_deque_to_new_array(const collections_deque_entrie
769759 return values ;
770760}
771761
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-
786762PHP_METHOD (Collections_Deque , toArray )
787763{
788764 ZEND_PARSE_PARAMETERS_NONE ();
@@ -1087,14 +1063,14 @@ PHP_METHOD(Collections_Deque, pop)
10871063 collections_deque_try_shrink_capacity (intern , old_size );
10881064}
10891065
1090- PHP_METHOD (Collections_Deque , top )
1066+ PHP_METHOD (Collections_Deque , last )
10911067{
10921068 ZEND_PARSE_PARAMETERS_NONE ();
10931069
10941070 const collections_deque * intern = Z_DEQUE_P (ZEND_THIS );
10951071 const size_t old_size = intern -> array .size ;
10961072 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 );
10981074 RETURN_THROWS ();
10991075 }
11001076
@@ -1126,14 +1102,14 @@ PHP_METHOD(Collections_Deque, shift)
11261102 collections_deque_try_shrink_capacity (intern , old_size );
11271103}
11281104
1129- PHP_METHOD (Collections_Deque , bottom )
1105+ PHP_METHOD (Collections_Deque , first )
11301106{
11311107 ZEND_PARSE_PARAMETERS_NONE ();
11321108
11331109 const collections_deque * intern = Z_DEQUE_P (ZEND_THIS );
11341110 DEBUG_ASSERT_CONSISTENT_DEQUE (& intern -> array );
11351111 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 );
11371113 RETURN_THROWS ();
11381114 }
11391115
@@ -1152,45 +1128,6 @@ PHP_METHOD(Collections_Deque, offsetUnset)
11521128 RETURN_THROWS ();
11531129}
11541130
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-
11941131PHP_MINIT_FUNCTION (collections_deque )
11951132{
11961133 collections_ce_Deque = register_class_Collections_Deque (zend_ce_aggregate , zend_ce_countable , php_json_serializable_ce , zend_ce_arrayaccess );
0 commit comments