diff options
author | Michal Brašna <michal.brasna@gmail.com> | 2013-11-26 12:44:02 +0100 |
---|---|---|
committer | Michal Brašna <michal.brasna@gmail.com> | 2013-11-26 12:44:02 +0100 |
commit | 62b4cc0fa103bb8f9d0cc2a9a44ad65d76c6d1cc (patch) | |
tree | a463db7c94c6bdfe9c287aef3a144242dcb8968f /lib/SqlFormatter.php | |
parent | 51a660e97b59f91b814eeee6e0a38e3cd726dd30 (diff) | |
download | sql-formatter-62b4cc0fa103bb8f9d0cc2a9a44ad65d76c6d1cc.zip sql-formatter-62b4cc0fa103bb8f9d0cc2a9a44ad65d76c6d1cc.tar.gz sql-formatter-62b4cc0fa103bb8f9d0cc2a9a44ad65d76c6d1cc.tar.bz2 |
Optimized speed of initializing reserved words list.
Diffstat (limited to 'lib/SqlFormatter.php')
-rw-r--r-- | lib/SqlFormatter.php | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php index 0efd8db..d921333 100644 --- a/lib/SqlFormatter.php +++ b/lib/SqlFormatter.php @@ -178,8 +178,10 @@ class SqlFormatter { if (self::$init) return; - // Sort reserved word list from longest word to shortest - usort(self::$reserved, array('SqlFormatter', 'sortLength')); + // Sort reserved word list from longest word to shortest, 3x faster than usort + $reservedMap = array_combine(self::$reserved, array_map('strlen', self::$reserved)); + arsort($reservedMap); + self::$reserved = array_keys($reservedMap); // Set up regular expressions self::$regex_boundaries = '('.implode('|',array_map(array('SqlFormatter', 'quote_regex'),self::$boundaries)).')'; @@ -1031,19 +1033,6 @@ class SqlFormatter } /** - * Helper function for sorting the list of reserved words by length - * - * @param String $a The first string - * @param String $b The second string - * - * @return int The comparison of the string lengths - */ - private static function sortLength($a, $b) - { - return strlen($b) - strlen($a); - } - - /** * Helper function for building regular expressions for reserved words and boundary characters * * @param String $a The string to be quoted |