Index: /CMT/HEAD/ChangeLog
===================================================================
--- /CMT/HEAD/ChangeLog	(revision 607)
+++ /CMT/HEAD/ChangeLog	(revision 608)
@@ -1,2 +1,17 @@
+2012-04-05    <rybkin@lal.in2p3.fr> 483
+
+	* source/cmt_project.h: In class Project function find_in_cmt_paths, add
+	second boolean parameter to specify whether first argument is real path
+	* source/cmt_project.cxx: In class Project, in function find_in_cmt_paths,
+	do not call CmtSystem::realpath_ if boolean parameter is true, in function
+	order_all, make use of m_realpath from class Use
+	* source/cmt_use.h: In class Use, introduce member m_realpath to hold
+	canonicalized absolute real_path, and member function get_realpath
+	* source/cmt_use.cxx: In class Use, in function change_path, calculate
+	m_realpath, in functions get_cmtpath_and_offset and get_strategy, make use
+	of m_realpath when calling Project::find_in_cmt_paths
+	* source/cmt_symbol.cxx: In find_path_entry helper function, introduce
+	static cache of real paths in order to optimise CmtSystem::realpath_ usage
+	
 2012-04-03    <rybkin@lal.in2p3.fr> 482
 
Index: /CMT/HEAD/source/cmt_project.cxx
===================================================================
--- /CMT/HEAD/source/cmt_project.cxx	(revision 607)
+++ /CMT/HEAD/source/cmt_project.cxx	(revision 608)
@@ -987,13 +987,22 @@
 
   Use& use = Use::current();
-  cmt_string current_path (Cmt::get_current_dir ());
+  cmt_string current_path;
+  cmt_string current_path_real;
   if (use.located ())
     {
-      current_path = use.real_path;
-      CmtMessage::verbose ("Using current use real_path `" + current_path + "'");
-    }
-
-  cmt_string current_path_real;
-  if (!CmtSystem::realpath_ (current_path, current_path_real))
+      current_path_real = use.get_realpath ();
+      if (current_path_real.size ())
+	CmtMessage::verbose ("Using current use realpath `" + current_path_real + "'");
+      else
+	{
+	  current_path = use.real_path;
+	  CmtMessage::verbose ("Using current use real_path `" + current_path + "'");
+	}
+    }
+  else
+    current_path = Cmt::get_current_dir ();
+
+  if (0 == current_path_real.size () &&
+      !CmtSystem::realpath_ (current_path, current_path_real))
     {
       CmtError::set (CmtError::file_access_error, "Cannot compute real path `" +
@@ -1650,5 +1659,5 @@
 
 //----------------------------------------------------------
-cmt_string Project::find_in_cmt_paths (const cmt_string& path)
+cmt_string Project::find_in_cmt_paths (const cmt_string& path, bool realpath)
 {
   //const cmt_string pwd = CmtSystem::pwd ();
@@ -1657,5 +1666,7 @@
   cmt_string path_real;
   //cerr << "realpath_: find_in_cmt_paths" << endl;
-  if (!CmtSystem::realpath_ (path, path_real))
+  if (realpath)
+    path_real = path;
+  else if (!CmtSystem::realpath_ (path, path_real))
     return ("");
 
Index: /CMT/HEAD/source/cmt_project.h
===================================================================
--- /CMT/HEAD/source/cmt_project.h	(revision 607)
+++ /CMT/HEAD/source/cmt_project.h	(revision 608)
@@ -127,5 +127,5 @@
   static void scan_paths_for_package (PathScanner& scanner, const cmt_string& name);
 
-  static cmt_string find_in_cmt_paths (const cmt_string& path);
+  static cmt_string find_in_cmt_paths (const cmt_string& path, bool realpath = false);
 
   static void fill_cmtpaths (cmt_string& buffer);
Index: /CMT/HEAD/source/cmt_symbol.cxx
===================================================================
--- /CMT/HEAD/source/cmt_symbol.cxx	(revision 607)
+++ /CMT/HEAD/source/cmt_symbol.cxx	(revision 608)
@@ -2223,18 +2223,19 @@
 {
   static const cmt_string path_separator = CmtSystem::path_separator ();
-
-  //  cmt_string here = CmtSystem::pwd ();
-  cmt_string rvalue = value;
-
-  /*
-  if (CmtSystem::cd (value))
-    {
-      rvalue = CmtSystem::pwd ();
-    }
-  else
-  */
-  if (!CmtSystem::realpath_ (value, rvalue))
-    {
-      CmtSystem::compress_path (rvalue);
+  static cmt_vmap <cmt_string, cmt_string> realpaths;
+
+  cmt_string rvalue;
+  const cmt_string * prvalue;
+
+  if (!(prvalue = realpaths.find (value)))
+    {
+      if (!CmtSystem::realpath_ (value, rvalue))
+	{
+	  rvalue = value;
+	  CmtSystem::compress_path (rvalue);
+	}
+      prvalue = &rvalue;
+      realpaths.add (value, rvalue);
+      //      cerr << "realpaths.add: " << value << " , " << rvalue << endl;
     }
 
@@ -2247,18 +2248,19 @@
     {
       const cmt_string& item = items[i];
-      cmt_string ritem = item;
-      /*
-      if (CmtSystem::cd (item))
+      cmt_string ritem;
+      const cmt_string * pritem;
+
+      if (!(pritem = realpaths.find (item)))
 	{
-	  ritem = CmtSystem::pwd ();
+	  if (!CmtSystem::realpath_ (item, ritem))
+	    {
+	      ritem = item;
+	      CmtSystem::compress_path (ritem);
+	    }
+	  pritem = &ritem;
+	  realpaths.add (item, ritem);
+	  //  cerr << "realpaths.add: " << item << " , " << ritem << endl;
 	}
-      else
-      */
-      if (!CmtSystem::realpath_ (item, ritem))
-	{
-	  CmtSystem::compress_path (ritem);
-	}
-
-      if (ritem == rvalue)
+      if (*pritem == *prvalue)
 	{
 	  found = true;
@@ -2267,5 +2269,4 @@
     }
 
-  //  CmtSystem::cd (here);
   return (found);
 }
Index: /CMT/HEAD/source/cmt_use.cxx
===================================================================
--- /CMT/HEAD/source/cmt_use.cxx	(revision 607)
+++ /CMT/HEAD/source/cmt_use.cxx	(revision 608)
@@ -1853,4 +1853,5 @@
   manager   = "";
   real_path = "";
+  m_realpath = "";
 
   prefix    = "";
@@ -1930,4 +1931,5 @@
 
   real_path = "";
+  m_realpath = "";
 
   if (new_path != "")
@@ -1947,4 +1949,11 @@
 
       CmtSystem::compress_path (real_path);
+      if (!CmtSystem::realpath_ (real_path, m_realpath))
+	{
+	  CmtError::set (CmtError::file_access_error, "Cannot compute real path `" +
+			 real_path + "'");
+	  CmtError::print ();
+	  return;
+	}
     }
   
@@ -3559,6 +3568,9 @@
   offset = "";
 
-  cmtpath = Project::find_in_cmt_paths (real_path);
-  Project* p = Project::find_by_cmtpath (cmtpath);
+  cmtpath = m_realpath.size ()
+    ? Project::find_in_cmt_paths (m_realpath, true)
+    : Project::find_in_cmt_paths (real_path)
+    ;
+  const Project* p = Project::find_by_cmtpath (cmtpath);
 
   //  if (cmtpath != "")
@@ -3574,5 +3586,7 @@
       //      offset.replace (cmtpath, empty_string);
       //cerr << "realpath_: get_cmtpath_and_offset" << endl;
-      if (!CmtSystem::realpath_ (real_path, offset))
+      if (0 != m_realpath.size ())
+	offset = m_realpath;
+      else if (!CmtSystem::realpath_ (real_path, offset))
 	{
 	  CmtError::set (CmtError::file_access_error, "Cannot compute real path `" +
@@ -3605,5 +3619,10 @@
 bool Use::get_strategy (const cmt_string& name) const
 {
-  const Project* p = Project::find_by_cmtpath (Project::find_in_cmt_paths (real_path));
+  const Project* p =
+    Project::find_by_cmtpath (m_realpath.size ()
+			      ? Project::find_in_cmt_paths (m_realpath, true)
+			      : Project::find_in_cmt_paths (real_path)
+			      );
+  //  const Project* p = Project::find_by_cmtpath (Project::find_in_cmt_paths (real_path));
 
   bool strategy;
Index: /CMT/HEAD/source/cmt_use.h
===================================================================
--- /CMT/HEAD/source/cmt_use.h	(revision 607)
+++ /CMT/HEAD/source/cmt_use.h	(revision 608)
@@ -110,4 +110,5 @@
   void get_cmtpath_and_offset (cmt_string& cmtpath, cmt_string& offset) const;
   bool get_strategy (const cmt_string& name) const;
+  inline const cmt_string& get_realpath () const { return m_realpath; }
 
   void fill_includes_macro (cmt_string& buffer) const;
@@ -246,4 +247,5 @@
 
   cmt_regexp m_head_version; 
+  cmt_string m_realpath; /* canonicalized absolute real_path */
 
   friend class UseProjectAction;
