Skip to content

Commit 5324acf

Browse files
committed
Refactor
1 parent 99f0492 commit 5324acf

25 files changed

+23
-69
lines changed

php_phongo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int*
159159
{
160160
*table = NULL;
161161
*n = 0;
162-
return zend_std_get_properties(object);
162+
return object->handlers->get_properties(object);
163163
}
164164

165165
PHP_MINIT_FUNCTION(mongodb) /* {{{ */

php_phongo.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,6 @@ ZEND_TSRMLS_CACHE_EXTERN()
6060

6161
zend_object_handlers* phongo_get_std_object_handlers(void);
6262

63-
#define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \
64-
do { \
65-
if (is_temp) { \
66-
ALLOC_HASHTABLE(props); \
67-
zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \
68-
} else if ((intern)->properties) { \
69-
(props) = (intern)->properties; \
70-
} else { \
71-
ALLOC_HASHTABLE(props); \
72-
zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \
73-
(intern)->properties = (props); \
74-
} \
75-
} while (0)
76-
77-
#define PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props) \
78-
do { \
79-
if (is_temp) { \
80-
zend_hash_destroy((props)); \
81-
FREE_HASHTABLE(props); \
82-
} \
83-
} while (0)
84-
8563
#define PHONGO_ZVAL_EXCEPTION_NAME(e) (ZSTR_VAL(e->ce->name))
8664

8765
#define PHONGO_SET_CREATED_BY_PID(intern) \

src/BSON/Binary.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, boo
7070

7171
intern = Z_OBJ_BINARY(object);
7272

73-
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2);
73+
props = zend_std_get_properties(object);
7474

7575
if (!intern->data) {
7676
return props;

src/BSON/DBPointer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is
7171

7272
intern = Z_OBJ_DBPOINTER(object);
7373

74-
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2);
74+
props = zend_std_get_properties(object);
7575

7676
if (!intern->ref) {
7777
return props;

src/BSON/Decimal128.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object,
6161

6262
intern = Z_OBJ_DECIMAL128(object);
6363

64-
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1);
64+
props = zend_std_get_properties(object);
6565

6666
if (!intern->initialized) {
6767
return props;

src/BSON/Document.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, b
6262

6363
intern = Z_OBJ_DOCUMENT(object);
6464

65-
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size);
65+
props = zend_std_get_properties(object);
6666

6767
if (!intern->bson) {
6868
return props;
@@ -514,17 +514,13 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i
514514
state.map.document.type = PHONGO_TYPEMAP_BSON;
515515
if (!php_phongo_bson_to_zval_ex(intern->bson, &state)) {
516516
zval_ptr_dtor(&state.zchild);
517-
goto failure;
517+
return NULL;
518518
}
519519

520520
zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild);
521521
}
522522

523523
return props;
524-
525-
failure:
526-
PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props);
527-
return NULL;
528524
}
529525

530526
static HashTable* php_phongo_document_get_properties(zend_object* object)

src/BSON/Int64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_tem
6969

7070
intern = Z_OBJ_INT64(object);
7171

72-
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2);
72+
props = zend_std_get_properties(object);
7373

7474
if (!intern->initialized) {
7575
return props;

src/BSON/Iterator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object, b
160160

161161
intern = Z_OBJ_ITERATOR(object);
162162

163-
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1);
163+
props = zend_std_get_properties(object);
164164

165165
zend_hash_str_update(props, "bson", sizeof("bson") - 1, &intern->bson);
166166
Z_TRY_ADDREF(intern->bson);

src/BSON/Javascript.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i
7676

7777
intern = Z_OBJ_JAVASCRIPT(object);
7878

79-
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2);
79+
props = zend_std_get_properties(object);
8080

8181
if (!intern->code) {
8282
return props;
@@ -94,7 +94,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i
9494
PHONGO_BSON_INIT_STATE(state);
9595
if (!php_phongo_bson_to_zval_ex(intern->scope, &state)) {
9696
zval_ptr_dtor(&state.zchild);
97-
goto failure;
97+
return NULL;
9898
}
9999

100100
zend_hash_str_update(props, "scope", sizeof("scope") - 1, &state.zchild);
@@ -107,10 +107,6 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i
107107
}
108108

109109
return props;
110-
111-
failure:
112-
PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props);
113-
return NULL;
114110
}
115111

116112
/* Construct a new BSON Javascript type. The scope is a document mapping

src/BSON/ObjectId.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b
8484

8585
intern = Z_OBJ_OBJECTID(object);
8686

87-
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1);
87+
props = zend_std_get_properties(object);
8888

8989
if (!intern->initialized) {
9090
return props;

0 commit comments

Comments
 (0)