Przeglądaj źródła

[Templating] made a small speed optimization to some helpers

Fabien Potencier 15 lat temu
rodzic
commit
6b90eeb69c

+ 5 - 5
src/Symfony/Components/Templating/Helper/JavascriptsHelper.php

@@ -57,19 +57,19 @@ class JavascriptsHelper extends Helper
    */
   public function __toString()
   {
-    $html = array();
+    $html = '';
     foreach ($this->javascripts as $path => $attributes)
     {
-      $atts = array();
+      $atts = '';
       foreach ($attributes as $key => $value)
       {
-        $atts[] = sprintf('%s="%s"', $key, $this->engine->escape($value));
+        $atts .= ' '.sprintf('%s="%s"', $key, $this->engine->escape($value));
       }
 
-      $html[] = sprintf('<script type="text/javascript" src="%s" %s></script>', $path, implode(' ', $atts));
+      $html .= sprintf('<script type="text/javascript" src="%s"%s></script>', $path, $atts)."\n";
     }
 
-    return implode("\n", $html);
+    return $html;
   }
 
   /**

+ 5 - 5
src/Symfony/Components/Templating/Helper/StylesheetsHelper.php

@@ -57,19 +57,19 @@ class StylesheetsHelper extends Helper
    */
   public function __toString()
   {
-    $html = array();
+    $html = '';
     foreach ($this->stylesheets as $path => $attributes)
     {
-      $atts = array();
+      $atts = '';
       foreach ($attributes as $key => $value)
       {
-        $atts[] = sprintf('%s="%s"', $key, $this->engine->escape($value));
+        $atts .= ' '.sprintf('%s="%s"', $key, $this->engine->escape($value));
       }
 
-      $html[] = sprintf('<link href="%s" rel="stylesheet" type="text/css" %s />', $path, implode(' ', $atts));
+      $html .= sprintf('<link href="%s" rel="stylesheet" type="text/css"%s />', $path, $atts)."\n";
     }
 
-    return implode("\n", $html);
+    return $html;
   }
 
   /**