From fe4fc7f8dcfcb74fa4a17c2d80b633372ae461a7 Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Thu, 2 Aug 2012 08:02:49 +0200
Subject: [PATCH] Fix: increase speed

---
 htdocs/core/lib/functions.lib.php | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 36350e1fb4c..9a20d25f431 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -226,12 +226,17 @@ function dol_getprefix()
  *  To link to a module file from a core file, then this function can be used
  *
  * 	@param	string	$relpath	Relative path to file (Ie: mydir/myfile, ../myfile, ...)
+ * 	@param	string	$classname	Class name
  *  @return int					false if include fails.
  */
-function dol_include_once($relpath)
+function dol_include_once($relpath, $classname='')
 {
     global $conf,$langs,$user,$mysoc;   // Other global var must be retreived with $GLOBALS['var']
-    return @include_once(dol_buildpath($relpath));
+    if (! empty($classname) && ! class_exists($classname)) {
+    	return @include dol_buildpath($relpath);
+    } else {
+    	return @include_once dol_buildpath($relpath);
+    }
 }
 
 
@@ -242,7 +247,7 @@ function dol_include_once($relpath)
  *  @param	int		$type		0=Used for a Filesystem path, 1=Used for an URL path (output relative), 2=Used for an URL path (output full path)
  *  @return string				Full filsystem path (if mode=0), Full url path (if mode=1)
  */
-function dol_buildpath($path,$type=0)
+function dol_buildpath($path, $type=0)
 {
     if (empty($type))	// For a filesystem path
     {
@@ -270,7 +275,7 @@ function dol_buildpath($path,$type=0)
                 }
             }
         }
-        if ($type == 2)
+        else if ($type == 2)
         {
             $res = DOL_MAIN_URL_ROOT.$path;      // Standard value
             if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT)            // We check only if alternate feature is used
-- 
GitLab