Skip to content

Commit ca423d7

Browse files
committed
Refactor Document::get() and property handlers
1 parent ef3f12e commit ca423d7

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

Diff for: src/BSON/Document.c

+7-17
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,8 @@ static PHP_METHOD(MongoDB_BSON_Document, get)
234234

235235
intern = Z_DOCUMENT_OBJ_P(getThis());
236236

237-
if (!php_phongo_document_get(intern, key, key_len, return_value, false)) {
238-
// Exception already thrown
239-
RETURN_NULL();
240-
}
237+
// May throw, in which case we do nothing
238+
php_phongo_document_get(intern, key, key_len, return_value, false);
241239
}
242240

243241
static PHP_METHOD(MongoDB_BSON_Document, getIterator)
@@ -595,13 +593,9 @@ static HashTable* php_phongo_document_get_properties(zend_object* object)
595593

596594
zval* php_phongo_document_read_property(zend_object* object, zend_string* member, int type, void** cache_slot, zval* rv)
597595
{
598-
php_phongo_document_t* intern;
599-
char* key = ZSTR_VAL(member);
600-
size_t key_len = ZSTR_LEN(member);
601-
602-
intern = Z_OBJ_DOCUMENT(object);
596+
php_phongo_document_t* intern = Z_OBJ_DOCUMENT(object);
603597

604-
if (!php_phongo_document_get(intern, key, key_len, rv, type == BP_VAR_IS)) {
598+
if (!php_phongo_document_get(intern, ZSTR_VAL(member), ZSTR_LEN(member), rv, type == BP_VAR_IS)) {
605599
// Exception already thrown
606600
return &EG(uninitialized_zval);
607601
}
@@ -615,15 +609,11 @@ zval* php_phongo_document_write_property(zend_object* object, zend_string* membe
615609
return value;
616610
}
617611

618-
int php_phongo_document_has_property(zend_object* object, zend_string* name, int has_set_exists, void** cache_slot)
612+
int php_phongo_document_has_property(zend_object* object, zend_string* member, int has_set_exists, void** cache_slot)
619613
{
620-
php_phongo_document_t* intern;
621-
char* key = ZSTR_VAL(name);
622-
size_t key_len = ZSTR_LEN(name);
623-
624-
intern = Z_OBJ_DOCUMENT(object);
614+
php_phongo_document_t* intern = Z_OBJ_DOCUMENT(object);
625615

626-
return php_phongo_document_has(intern, key, key_len);
616+
return php_phongo_document_has(intern, ZSTR_VAL(member), ZSTR_LEN(member));
627617
}
628618

629619
void php_phongo_document_unset_property(zend_object* object, zend_string* member, void** cache_slot)

0 commit comments

Comments
 (0)