Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added query micro-optimization #209

Merged
merged 1 commit into from

4 participants

@dlsniper

This adds a micro-optimization to the query and also exposes better the function calls to the profilers like XDebug or XHProf.

@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-356

lib/Doctrine/DBAL/Connection.php
@@ -739,7 +739,15 @@ public function query()
}
try {
- $statement = call_user_func_array(array($this->_conn, 'query'), $args);
+ switch(func_num_args()) {
+ case 1: $statement = $this->_conn->query($args[0]); break;
@stof
stof added a note

Please fix the formatting:

switch (func_num_args()) {
    case 0:
        $statement = $this->_conn->query();
        break;
    case 1:
        $statement = $this->_conn->query($args[0]);
        break;
}
@stof
stof added a note

btw, I think you can remove the case for 0 as it should never happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@beberlei
Owner

What does this help with xhprof? cant you see the query + args in the parent call?

@dlsniper

@beberlei while you can see them in the parent function this is just a bonus over the micro-optimization benefits from changing the call from call_user_func_array() to direct call type like this.

@beberlei beberlei merged commit 1d8d6bc into doctrine:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 7, 2012
  1. @dlsniper
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 2 deletions.
  1. +12 −2 lib/Doctrine/DBAL/Connection.php
View
14 lib/Doctrine/DBAL/Connection.php
@@ -739,9 +739,19 @@ public function query()
}
try {
- $statement = call_user_func_array(array($this->_conn, 'query'), $args);
+ switch (func_num_args()) {
+ case 1:
+ $statement = $this->_conn->query($args[0]);
+ break;
+ case 2:
+ $statement = $this->_conn->query($args[0], $args[1]);
+ break;
+ default:
+ $statement = call_user_func_array(array($this->_conn, 'query'), $args);
+ break;
+ }
} catch (\Exception $ex) {
- throw DBALException::driverExceptionDuringQuery($ex, func_get_arg(0));
+ throw DBALException::driverExceptionDuringQuery($ex, $args[0]);
}
$statement->setFetchMode($this->_defaultFetchMode);
Something went wrong with that request. Please try again.