Skip to content

Commit 145ddda

Browse files
committed
PHPC-353: Return early when there are no options to apply
This avoids copying the client's existing RP or WC struct for no reason.
1 parent 0156489 commit 145ddda

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

php_phongo.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,17 @@ bool php_phongo_apply_rp_options_to_client(mongoc_client_t *client, bson_t *opti
16191619
return false;
16201620
}
16211621

1622+
/* Return early if there are no options to apply */
1623+
if (bson_empty0(options)) {
1624+
return true;
1625+
}
1626+
1627+
if (!bson_iter_init_find_case(&iter, options, "slaveok") &&
1628+
!bson_iter_init_find_case(&iter, options, "readpreference") &&
1629+
!bson_iter_init_find_case(&iter, options, "readpreferencetags")) {
1630+
return true;
1631+
}
1632+
16221633
new_rp = mongoc_read_prefs_copy(old_rp);
16231634

16241635
if (bson_iter_init_find_case(&iter, options, "slaveok") && BSON_ITER_HOLDS_BOOL(&iter)) {
@@ -1694,6 +1705,18 @@ bool php_phongo_apply_wc_options_to_client(mongoc_client_t *client, bson_t *opti
16941705
return false;
16951706
}
16961707

1708+
/* Return early if there are no options to apply */
1709+
if (bson_empty0(options)) {
1710+
return true;
1711+
}
1712+
1713+
if (!bson_iter_init_find_case(&iter, options, "journal") &&
1714+
!bson_iter_init_find_case(&iter, options, "safe") &&
1715+
!bson_iter_init_find_case(&iter, options, "w") &&
1716+
!bson_iter_init_find_case(&iter, options, "wtimeoutms")) {
1717+
return true;
1718+
}
1719+
16971720
wtimeoutms = mongoc_write_concern_get_wtimeout(old_wc);
16981721

16991722
new_wc = mongoc_write_concern_copy(old_wc);

0 commit comments

Comments
 (0)