@@ -1043,15 +1043,8 @@ PHP_METHOD(Vector, offsetSet)
1043
1043
spl_vector_set_value_at_offset (Z_OBJ_P (ZEND_THIS ), offset , value );
1044
1044
}
1045
1045
1046
- PHP_METHOD ( Vector , push )
1046
+ static zend_always_inline void spl_vector_push ( spl_vector * intern , zval * value )
1047
1047
{
1048
- zval * value ;
1049
-
1050
- ZEND_PARSE_PARAMETERS_START (1 , 1 )
1051
- Z_PARAM_ZVAL (value )
1052
- ZEND_PARSE_PARAMETERS_END ();
1053
-
1054
- spl_vector * intern = Z_VECTOR_P (ZEND_THIS );
1055
1048
const size_t old_size = intern -> array .size ;
1056
1049
const size_t old_capacity = intern -> array .capacity ;
1057
1050
@@ -1063,6 +1056,17 @@ PHP_METHOD(Vector, push)
1063
1056
intern -> array .size ++ ;
1064
1057
}
1065
1058
1059
+ PHP_METHOD (Vector , push )
1060
+ {
1061
+ zval * value ;
1062
+
1063
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
1064
+ Z_PARAM_ZVAL (value )
1065
+ ZEND_PARSE_PARAMETERS_END ();
1066
+
1067
+ spl_vector_push (Z_VECTOR_P (ZEND_THIS ), value );
1068
+ }
1069
+
1066
1070
PHP_METHOD (Vector , pop )
1067
1071
{
1068
1072
ZEND_PARSE_PARAMETERS_NONE ();
@@ -1134,35 +1138,35 @@ PHP_METHOD(Vector, jsonSerialize)
1134
1138
1135
1139
static void spl_vector_write_dimension (zend_object * object , zval * offset_zv , zval * value )
1136
1140
{
1141
+ spl_vector * intern = spl_vector_from_object (object );
1137
1142
if (!offset_zv ) {
1138
- zend_throw_exception ( spl_ce_RuntimeException , "[] operator not supported for Vector" , 0 );
1143
+ spl_vector_push ( intern , value );
1139
1144
return ;
1140
1145
}
1141
1146
1142
1147
zend_long offset ;
1143
1148
CONVERT_OFFSET_TO_LONG_OR_THROW (offset , offset_zv );
1144
1149
1145
- const spl_vector * intern = spl_vector_from_object (object );
1146
1150
if (offset < 0 || offset >= intern -> array .size ) {
1147
1151
zend_throw_exception (spl_ce_OutOfBoundsException , "Index invalid or out of range" , 0 );
1148
1152
return ;
1149
1153
}
1154
+ ZVAL_DEREF (value );
1150
1155
spl_vector_set_value_at_offset (object , offset , value );
1151
1156
}
1152
1157
1153
1158
static zval * spl_vector_read_dimension (zend_object * object , zval * offset_zv , int type , zval * rv )
1154
1159
{
1155
- if (!offset_zv ) {
1156
- zend_throw_exception (spl_ce_RuntimeException , "[] operator not supported for Vector" , 0 );
1157
- return NULL ;
1160
+ if (UNEXPECTED (!offset_zv || Z_ISUNDEF_P (offset_zv ))) {
1161
+ return & EG (uninitialized_zval );
1158
1162
}
1159
1163
1160
1164
zend_long offset ;
1161
1165
CONVERT_OFFSET_TO_LONG_OR_THROW_RETURN_NULLPTR (offset , offset_zv );
1162
1166
1163
1167
const spl_vector * intern = spl_vector_from_object (object );
1164
1168
1165
- if (offset < 0 || offset >= intern -> array .size ) {
1169
+ if (UNEXPECTED ( offset < 0 || offset >= intern -> array .size ) ) {
1166
1170
if (type != BP_VAR_IS ) {
1167
1171
zend_throw_exception (spl_ce_OutOfBoundsException , "Index out of range" , 0 );
1168
1172
}
@@ -1172,6 +1176,31 @@ static zval *spl_vector_read_dimension(zend_object *object, zval *offset_zv, int
1172
1176
}
1173
1177
}
1174
1178
1179
+ static int spl_vector_has_dimension (zend_object * object , zval * offset_zv , int check_empty )
1180
+ {
1181
+ zend_long offset ;
1182
+ if (UNEXPECTED (Z_TYPE_P (offset_zv ) != IS_LONG )) {
1183
+ offset = spl_offset_convert_to_long (offset_zv );
1184
+ if (UNEXPECTED (EG (exception ))) {
1185
+ return 0 ;
1186
+ }
1187
+ } else {
1188
+ offset = Z_LVAL_P (offset_zv );
1189
+ }
1190
+
1191
+ const spl_vector * intern = spl_vector_from_object (object );
1192
+
1193
+ if (UNEXPECTED (offset < 0 || offset >= intern -> array .size )) {
1194
+ return 0 ;
1195
+ }
1196
+
1197
+ zval * val = & intern -> array .entries [offset ];
1198
+ if (check_empty ) {
1199
+ return zend_is_true (val );
1200
+ }
1201
+ return Z_TYPE_P (val ) != IS_NULL ;
1202
+ }
1203
+
1175
1204
PHP_MINIT_FUNCTION (spl_vector )
1176
1205
{
1177
1206
spl_ce_Vector = register_class_Vector (zend_ce_aggregate , zend_ce_countable , php_json_serializable_ce , zend_ce_arrayaccess );
@@ -1189,6 +1218,7 @@ PHP_MINIT_FUNCTION(spl_vector)
1189
1218
1190
1219
spl_handler_Vector .read_dimension = spl_vector_read_dimension ;
1191
1220
spl_handler_Vector .write_dimension = spl_vector_write_dimension ;
1221
+ spl_handler_Vector .has_dimension = spl_vector_has_dimension ;
1192
1222
1193
1223
spl_ce_Vector -> ce_flags |= ZEND_ACC_FINAL | ZEND_ACC_NO_DYNAMIC_PROPERTIES ;
1194
1224
spl_ce_Vector -> get_iterator = spl_vector_get_iterator ;
0 commit comments