From 6d0057b13ced5a7991ad1b921c4c208895276a2e Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 2 Apr 2015 17:22:40 +0200 Subject: Improve performance of pygments->mime2lexer Normal arrays are rather slow when accessed sequentially. Use associative arrays and key lookups to reduce the render time of a multipaste with 180 items from 225ms to ~190ms. Signed-off-by: Florian Pritz --- application/libraries/Pygments.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'application') diff --git a/application/libraries/Pygments.php b/application/libraries/Pygments.php index 12f6d7037..3c99481d1 100644 --- a/application/libraries/Pygments.php +++ b/application/libraries/Pygments.php @@ -36,7 +36,7 @@ class Pygments { foreach (self::get_pygments_info() as $lexer) { $desc = $lexer['fullname']; - $name = $lexer['names'][0]; + $name = array_keys($lexer['names'])[0]; if ($desc == $last_desc) { continue; } @@ -146,13 +146,11 @@ class Pygments { if (array_key_exists($this->mimetype, $typearray)) return $typearray[$this->mimetype]; // fall back to pygments own list if not found in our list - $typearray = array(); foreach (self::get_pygments_info() as $lexer) { - foreach ($lexer['mimetypes'] as $type) { - $typearray[$type] = $lexer['names'][0]; + if (isset($lexer['mimetypes'][$this->mimetype])) { + return $lexer; } } - if (array_key_exists($this->mimetype, $typearray)) return $typearray[$this->mimetype]; if (strpos($this->mimetype, 'text/') === 0) return 'text'; -- cgit v1.2.3-24-g4f1b