Browse Source

Merge pull request #1180 from unikent/master

Performance enhancement for HTML Class.
Taylor Otwell 12 years ago
parent
commit
8ff052cbdb
1 changed files with 20 additions and 3 deletions
  1. 20 3
      laravel/html.php

+ 20 - 3
laravel/html.php

@@ -9,6 +9,13 @@ class HTML {
 	 */
 	public static $macros = array();
 
+	/**
+	 * Cache application encoding locally to save expensive calls to config::get().
+	 *
+	 * @var string
+	 */
+	public static $encoding = null;
+
 	/**
 	 * Registers a custom macro.
 	 *
@@ -31,7 +38,7 @@ class HTML {
 	 */
 	public static function entities($value)
 	{
-		return htmlentities($value, ENT_QUOTES, Config::get('application.encoding'), false);
+		return htmlentities($value, ENT_QUOTES, static::encoding(), false);
 	}
 
 	/**
@@ -42,7 +49,7 @@ class HTML {
 	 */
 	public static function decode($value)
 	{
-		return html_entity_decode($value, ENT_QUOTES, Config::get('application.encoding'));
+		return html_entity_decode($value, ENT_QUOTES, static::encoding());
 	}
 
 	/**
@@ -55,7 +62,7 @@ class HTML {
 	 */
 	public static function specialchars($value)
 	{
-		return htmlspecialchars($value, ENT_QUOTES, Config::get('application.encoding'), false);
+		return htmlspecialchars($value, ENT_QUOTES, static::encoding(), false);
 	}
 
 	/**
@@ -431,6 +438,16 @@ class HTML {
 		return $safe;
 	}
 
+	/**
+	 * Get the appliction.encoding without needing to request it from Config::get() each time.
+	 *
+	 * @return string
+	 */
+	protected static function encoding()
+	{
+		return static::$encoding ?: static::$encoding = Config::get('application.encoding');
+	}
+
 	/**
 	 * Dynamically handle calls to custom macros.
 	 *