diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 0774c37b9e7a346306e947386ad96df858c97a0c..002663290ff9bea06f678e4998c39ea6303c44fd 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -6,6 +6,7 @@ Drupal 7.51, xxxx-xx-xx (development version) - Exceptions thrown in dblog_watchdog() are now caught and ignored. - Clarified the warning that appears when modules are missing or have moved. - If the page title is "0", it is now displayed. +- Numerous small performance improvements. - Numerous small bugfixes. - Numerous API documentation improvements. diff --git a/includes/database/database.inc b/includes/database/database.inc index 21b7c22ac080feb89c8fe3f81a22435d9d6acf2e..6879f69916281c81f6f30af93a4d296ddb0d69a1 100644 --- a/includes/database/database.inc +++ b/includes/database/database.inc @@ -296,6 +296,20 @@ abstract class DatabaseConnection extends PDO { */ protected $prefixReplace = array(); + /** + * List of escaped database, table, and field names, keyed by unescaped names. + * + * @var array + */ + protected $escapedNames = array(); + + /** + * List of escaped aliases names, keyed by unescaped aliases. + * + * @var array + */ + protected $escapedAliases = array(); + function __construct($dsn, $username, $password, $driver_options = array()) { // Initialize and prepare the connection prefix. $this->setPrefix(isset($this->connectionOptions['prefix']) ? $this->connectionOptions['prefix'] : ''); @@ -919,11 +933,14 @@ public function schema() { * For some database drivers, it may also wrap the table name in * database-specific escape characters. * - * @return + * @return string * The sanitized table name string. */ public function escapeTable($table) { - return preg_replace('/[^A-Za-z0-9_.]+/', '', $table); + if (!isset($this->escapedNames[$table])) { + $this->escapedNames[$table] = preg_replace('/[^A-Za-z0-9_.]+/', '', $table); + } + return $this->escapedNames[$table]; } /** @@ -933,11 +950,14 @@ public function escapeTable($table) { * For some database drivers, it may also wrap the field name in * database-specific escape characters. * - * @return + * @return string * The sanitized field name string. */ public function escapeField($field) { - return preg_replace('/[^A-Za-z0-9_.]+/', '', $field); + if (!isset($this->escapedNames[$field])) { + $this->escapedNames[$field] = preg_replace('/[^A-Za-z0-9_.]+/', '', $field); + } + return $this->escapedNames[$field]; } /** @@ -948,11 +968,14 @@ public function escapeField($field) { * DatabaseConnection::escapeTable(), this doesn't allow the period (".") * because that is not allowed in aliases. * - * @return + * @return string * The sanitized field name string. */ public function escapeAlias($field) { - return preg_replace('/[^A-Za-z0-9_]+/', '', $field); + if (!isset($this->escapedAliases[$field])) { + $this->escapedAliases[$field] = preg_replace('/[^A-Za-z0-9_]+/', '', $field); + } + return $this->escapedAliases[$field]; } /**