Skip to content

Commit d32ed89

Browse files
committed
phongo_bson_append() can be static and get zval type internally
1 parent b6d0908 commit d32ed89

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/bson.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -981,12 +981,13 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
981981
zval_to_bson(object, flags, &child, NULL TSRMLS_CC);
982982
bson_append_document_end(bson, &child);
983983
}
984-
void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char *key, long key_len, int entry_type, zval *entry TSRMLS_DC)
984+
985+
static void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char *key, long key_len, zval *entry TSRMLS_DC)
985986
{
986987
#if PHP_VERSION_ID >= 70000
987988
try_again:
988989
#endif
989-
switch (entry_type)
990+
switch (Z_TYPE_P(entry))
990991
{
991992
case IS_NULL:
992993
bson_append_null(bson, key, key_len);
@@ -1046,17 +1047,16 @@ void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char
10461047

10471048
#if PHP_VERSION_ID >= 70000
10481049
case IS_INDIRECT:
1049-
phongo_bson_append(bson, flags, key, key_len, Z_TYPE_P(Z_INDIRECT_P(entry)), Z_INDIRECT_P(entry) TSRMLS_DC);
1050+
phongo_bson_append(bson, flags, key, key_len, Z_INDIRECT_P(entry) TSRMLS_DC);
10501051
break;
10511052

10521053
case IS_REFERENCE:
10531054
ZVAL_DEREF(entry);
1054-
entry_type = Z_TYPE_P(entry);
10551055
goto try_again;
10561056
#endif
10571057

10581058
default:
1059-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Got unsupported type %d '%s'", entry_type, zend_get_type_by_const(entry_type));
1059+
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Got unsupported type %d '%s'", Z_TYPE_P(entry), zend_get_type_by_const(Z_TYPE_P(entry)));
10601060
}
10611061
}
10621062

@@ -1239,7 +1239,7 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
12391239
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID,
12401240
member ? ZSTR_VAL(member) : ZSTR_VAL(key),
12411241
member ? ZSTR_LEN(member) : ZSTR_LEN(key),
1242-
Z_TYPE_P(value), value TSRMLS_CC);
1242+
value TSRMLS_CC);
12431243

12441244
if (member) {
12451245
zend_string_release(member);
@@ -1250,14 +1250,14 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
12501250
flags &= ~PHONGO_BSON_ADD_ID;
12511251
}
12521252
}
1253-
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID, ZSTR_VAL(key), ZSTR_LEN(key), Z_TYPE_P(value), value TSRMLS_CC);
1253+
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID, ZSTR_VAL(key), ZSTR_LEN(key), value TSRMLS_CC);
12541254
}
12551255
} else {
12561256
char numbuf[32];
12571257
const char *skey;
12581258
unsigned int skey_len = 0;
12591259
skey_len = bson_uint32_to_string(num_key, (const char **)&skey, numbuf, sizeof(numbuf));
1260-
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID, skey, skey_len, Z_TYPE_P(value), value TSRMLS_CC);
1260+
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID, skey, skey_len, value TSRMLS_CC);
12611261
}
12621262
} ZEND_HASH_FOREACH_END();
12631263
}
@@ -1304,7 +1304,7 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
13041304
} else {
13051305
key_len = bson_uint32_to_string(index, (const char **)&key, numbuf, sizeof(numbuf));
13061306
}
1307-
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID, key, key_len, Z_TYPE_PP(entry), *entry TSRMLS_CC);
1307+
phongo_bson_append(bson, flags & ~PHONGO_BSON_ADD_ID, key, key_len, *entry TSRMLS_CC);
13081308
}
13091309
#endif
13101310

0 commit comments

Comments
 (0)