From: andy at petdance dot com
Operating system: Any
PHP version: 5.2.4
PHP Bug Type: PostgreSQL related
Bug description: Teeny speedup patch in Postgres
Description:
------------
Not a bug at all. Just was looking at the code for the Postgres fetching,
and there are a couple of places where it's redundantly checking for
NULLness on a pointer. This patch fixes it.
Reproduce code:
---------------
--- ext/pgsql/pgsql-old.c 2007-10-19 10:03:42.166485760 -0500
+++ ext/pgsql/pgsql.c 2007-10-19 10:08:29.289836376 -0500
@@ -1992,7 +1992,6 @@
int i, num_fields, pgsql_row, use_row;
long row = -1;
char *element, *field_name;
- uint element_len;
zval *ctor_params = NULL;
zend_class_entry *ce = NULL;
@@ -2064,11 +2063,11 @@
}
} else {
element = PQgetvalue(pgsql_result, pgsql_row, i);
- element_len = (element ? strlen(element) : 0);
if (element) {
char *data;
int data_len;
int should_copy=0;
+ const uint element_len = strlen(element);
if (PG(magic_quotes_runtime)) {
data = php_addslashes(element,
element_len, &data_len, 0
TSRMLS_CC);
@@ -5712,7 +5711,7 @@
{
zval *row;
char *field_name, *element, *data;
- size_t num_fields, element_len, data_len;
+ size_t num_fields;
int pg_numrows, pg_row;
uint i;
assert(Z_TYPE_P(ret_array) == IS_ARRAY);
@@ -5730,8 +5729,9 @@
add_assoc_null(row, field_name);
} else {
element = PQgetvalue(pg_result, pg_row, i);
- element_len = (element ? strlen(element) : 0);
if (element) {
+ const size_t element_len =
strlen(element);
+ size_t data_len;
if (PG(magic_quotes_runtime)) {
data = php_addslashes(element,
element_len, &data_len, 0
TSRMLS_CC);
} else {
--
Edit bug report at http://bugs.php.net/?id=43041&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=43041&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=43041&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=43041&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=43041&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43041&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=43041&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43041&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43041&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43041&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43041&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43041&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=43041&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=43041&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43041&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43041&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43041&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43041&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43041&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43041&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43041&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43041&r=mysqlcfg