Skip to content

Commit 993129e

Browse files
authored
Use zend_array_is_list in phongo_is_array_or_document (#1961)
As it has some performance improvements, and is more readable than iterating through array keys to determine if the given value is a list or not
1 parent eb94b56 commit 993129e

1 file changed

Lines changed: 2 additions & 21 deletions

File tree

src/phongo_bson_encode.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static void phongo_zval_to_bson_internal(zval* data, phongo_field_path* field_pa
5353
static int phongo_is_array_or_document(zval* val)
5454
{
5555
HashTable* ht_data = HASH_OF(val);
56-
int count;
5756

5857
if (Z_TYPE_P(val) != IS_ARRAY) {
5958
if (Z_TYPE_P(val) == IS_OBJECT && instanceof_function(Z_OBJCE_P(val), phongo_packedarray_ce)) {
@@ -63,26 +62,8 @@ static int phongo_is_array_or_document(zval* val)
6362
return IS_OBJECT;
6463
}
6564

66-
count = ht_data ? zend_hash_num_elements(ht_data) : 0;
67-
if (count > 0) {
68-
zend_string* key;
69-
zend_ulong index, idx;
70-
71-
idx = 0;
72-
ZEND_HASH_FOREACH_KEY(ht_data, index, key)
73-
{
74-
if (key) {
75-
return IS_OBJECT;
76-
} else {
77-
if (index != idx) {
78-
return IS_OBJECT;
79-
}
80-
}
81-
idx++;
82-
}
83-
ZEND_HASH_FOREACH_END();
84-
} else {
85-
return Z_TYPE_P(val);
65+
if (!zend_array_is_list(ht_data)) {
66+
return IS_OBJECT;
8667
}
8768

8869
return IS_ARRAY;

0 commit comments

Comments
 (0)