Aleksander Machniak
2013-11-06 00de8ddf8d899a8c9a9ca89009f845f88eb7a6cc
Small performance improvements, use str_replace() instead of strtr(),
do not parse query if there are no params to replace,
keep one instance of (potentially long) query less in memory
1 files modified
13 ■■■■ changed files
program/lib/Roundcube/rcube_db.php 13 ●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_db.php
@@ -392,7 +392,7 @@
     */
    protected function _query($query, $offset, $numrows, $params)
    {
        $query = trim($query);
        $query = ltrim($query);
        $this->db_connect($this->dsn_select($query), true);
@@ -405,15 +405,14 @@
            $query = $this->set_limit($query, $numrows, $offset);
        }
        $params = (array) $params;
        // Because in Roundcube we mostly use queries that are
        // executed only once, we will not use prepared queries
        $pos = 0;
        $idx = 0;
        if (count($params)) {
        while ($pos = strpos($query, '?', $pos)) {
            if ($query[$pos+1] == '?') {  // skip escaped ?
                if ($query[$pos+1] == '?') {  // skip escaped '?'
                $pos += 2;
            }
            else {
@@ -423,9 +422,11 @@
                $pos += strlen($val);
            }
        }
        }
        // replace escaped ? back to normal
        $query = rtrim(strtr($query, array('??' => '?')), ';');
        // replace escaped '?' back to normal, see self::quote()
        $query = str_replace('??', '?', $query);
        $query = rtrim($query, " \t\n\r\0\x0B;");
        $this->debug($query);