Skip to content

Commit 005ff3e

Browse files
committed
Get rid of the hashes global hash
The idea came up in c7a86a3
1 parent eb4dcbb commit 005ff3e

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

ext/pgsql/pgsql.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,17 @@ static zend_function *pgsql_link_get_constructor(zend_object *object) {
160160
static void pgsql_link_free(pgsql_link_handle *link)
161161
{
162162
PGresult *res;
163-
zval *hash;
164163

165164
while ((res = PQgetResult(link->conn))) {
166165
PQclear(res);
167166
}
168167
PQfinish(link->conn);
169168
PGG(num_links)--;
170169

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

178172
link->conn = NULL;
173+
zend_string_release(link->hash);
179174
}
180175

181176
static void pgsql_link_free_obj(zend_object *obj)
@@ -406,7 +401,6 @@ static PHP_GINIT_FUNCTION(pgsql)
406401
memset(pgsql_globals, 0, sizeof(zend_pgsql_globals));
407402
/* Initialize notice message hash at MINIT only */
408403
zend_hash_init(&pgsql_globals->notices, 0, NULL, ZVAL_PTR_DTOR, 1);
409-
zend_hash_init(&pgsql_globals->hashes, 0, NULL, ZVAL_PTR_DTOR, 1);
410404
zend_hash_init(&pgsql_globals->regular_list, 0, NULL, ZVAL_PTR_DTOR, 1);
411405
}
412406

@@ -578,7 +572,6 @@ PHP_MSHUTDOWN_FUNCTION(pgsql)
578572
{
579573
UNREGISTER_INI_ENTRIES();
580574
zend_hash_destroy(&PGG(notices));
581-
zend_hash_destroy(&PGG(hashes));
582575
zend_hash_destroy(&PGG(regular_list));
583576

584577
return SUCCESS;
@@ -763,6 +756,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
763756
object_init_ex(return_value, pgsql_link_ce);
764757
link = Z_PGSQL_LINK_P(return_value);
765758
link->conn = pgsql;
759+
link->hash = zend_string_copy(str.s);
766760

767761
/* add it to the hash */
768762
ZVAL_COPY(&new_index_ptr, return_value);
@@ -772,11 +766,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
772766
* when the connection is closed. This uses the address of the connection rather than the
773767
* zend_resource, because the resource destructor is passed a stack copy of the resource
774768
* structure. */
775-
{
776-
zval tmp;
777-
ZVAL_STR_COPY(&tmp, str.s);
778-
zend_hash_index_update(&PGG(hashes), (uintptr_t) pgsql, &tmp);
779-
}
769+
780770
PGG(num_links)++;
781771
}
782772
/* set notice processor */

ext/pgsql/php_pgsql.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ typedef enum _php_pgsql_data_type {
145145

146146
typedef struct pgsql_link_handle {
147147
PGconn *conn;
148+
zend_string *hash;
148149
zend_object std;
149150
} pgsql_link_handle;
150151

0 commit comments

Comments
 (0)