Skip to content

Commit 09e569f

Browse files
committed
Get rid of the hashes global hash
The idea came up in c7a86a3
1 parent 0555a58 commit 09e569f

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

ext/pgsql/pgsql.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,17 @@ static zend_function *pgsql_link_get_constructor(zend_object *object) {
163163
static void pgsql_link_free(pgsql_link_handle *link)
164164
{
165165
PGresult *res;
166-
zval *hash;
167166

168167
while ((res = PQgetResult(link->conn))) {
169168
PQclear(res);
170169
}
171170
PQfinish(link->conn);
172171
PGG(num_links)--;
173172

174-
/* Remove connection hash for this link */
175-
hash = zend_hash_index_find(&PGG(hashes), (uintptr_t) link->conn);
176-
if (hash) {
177-
zend_hash_index_del(&PGG(hashes), (uintptr_t) link->conn);
178-
zend_hash_del(&PGG(regular_list), Z_STR_P(hash));
179-
}
173+
zend_hash_del(&PGG(regular_list), link->hash);
180174

181175
link->conn = NULL;
176+
zend_string_release(link->hash);
182177
}
183178

184179
static void pgsql_link_free_obj(zend_object *obj)
@@ -415,7 +410,6 @@ static PHP_GINIT_FUNCTION(pgsql)
415410
memset(pgsql_globals, 0, sizeof(zend_pgsql_globals));
416411
/* Initialize notice message hash at MINIT only */
417412
zend_hash_init(&pgsql_globals->notices, 0, NULL, ZVAL_PTR_DTOR, 1);
418-
zend_hash_init(&pgsql_globals->hashes, 0, NULL, ZVAL_PTR_DTOR, 1);
419413
zend_hash_init(&pgsql_globals->regular_list, 0, NULL, ZVAL_PTR_DTOR, 1);
420414
}
421415

@@ -588,7 +582,6 @@ PHP_MSHUTDOWN_FUNCTION(pgsql)
588582
{
589583
UNREGISTER_INI_ENTRIES();
590584
zend_hash_destroy(&PGG(notices));
591-
zend_hash_destroy(&PGG(hashes));
592585
zend_hash_destroy(&PGG(regular_list));
593586

594587
return SUCCESS;
@@ -605,7 +598,6 @@ PHP_RSHUTDOWN_FUNCTION(pgsql)
605598
{
606599
/* clean up notice messages */
607600
zend_hash_clean(&PGG(notices));
608-
zend_hash_clean(&PGG(hashes));
609601
zend_hash_clean(&PGG(regular_list));
610602
/* clean up persistent connection */
611603
zend_hash_apply(&EG(persistent_list), (apply_func_t) _rollback_transactions);
@@ -769,6 +761,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
769761
object_init_ex(return_value, pgsql_link_ce);
770762
link = Z_PGSQL_LINK_P(return_value);
771763
link->conn = pgsql;
764+
link->hash = zend_string_copy(str.s);
772765

773766
/* add it to the hash */
774767
ZVAL_COPY(&new_index_ptr, return_value);
@@ -778,11 +771,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
778771
* when the connection is closed. This uses the address of the connection rather than the
779772
* zend_resource, because the resource destructor is passed a stack copy of the resource
780773
* structure. */
781-
{
782-
zval tmp;
783-
ZVAL_STR_COPY(&tmp, str.s);
784-
zend_hash_index_update(&PGG(hashes), (uintptr_t) pgsql, &tmp);
785-
}
774+
786775
PGG(num_links)++;
787776
}
788777
/* set notice processor */

ext/pgsql/php_pgsql.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ typedef enum _php_pgsql_data_type {
146146

147147
typedef struct pgsql_link_handle {
148148
PGconn *conn;
149+
zend_string *hash;
149150
zend_object std;
150151
} pgsql_link_handle;
151152

@@ -187,7 +188,6 @@ ZEND_BEGIN_MODULE_GLOBALS(pgsql)
187188
int ignore_notices,log_notices;
188189
HashTable notices; /* notice message for each connection */
189190
pgsql_link_handle *default_link; /* default link when connection is omitted */
190-
HashTable hashes; /* hashes for each connection */
191191
HashTable regular_list; /* connection list */
192192
ZEND_END_MODULE_GLOBALS(pgsql)
193193

0 commit comments

Comments
 (0)