[Cmake-commits] [cmake-commits] king committed SystemTools.cxx 1.248 1.249 SystemTools.hxx.in 1.78 1.79

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Sep 22 13:02:23 EDT 2009


Update of /cvsroot/CMake/CMake/Source/kwsys
In directory public:/mounts/ram/cvs-serv9240/Source/kwsys

Modified Files:
	SystemTools.cxx SystemTools.hxx.in 
Log Message:
Optimize KWSys SystemTools::FileExists on Windows

We optimize this method by using the GetFileAttributesExA native Windows
API to check for file existence when possible.  For real Windows builds
we always use it.  For Cygwin we use cygwin_conv_to_win32_path to get a
native Windows path if possible and otherwise fall back to 'access'.

Cygwin-to-Windows path conversion and cache by Wojciech Migda.
See issue #8826.


Index: SystemTools.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/kwsys/SystemTools.cxx,v
retrieving revision 1.248
retrieving revision 1.249
diff -C 2 -d -r1.248 -r1.249
*** SystemTools.cxx	6 Aug 2009 23:01:13 -0000	1.248
--- SystemTools.cxx	22 Sep 2009 17:02:19 -0000	1.249
***************
*** 66,73 ****
  
  // Windows API.  Some parts used even on cygwin.
! #if defined(_WIN32)
  # include <windows.h>
  #endif
  
  // getpwnam doesn't exist on Windows and Cray Xt3/Catamount
  // same for TIOCGWINSZ
--- 66,78 ----
  
  // Windows API.  Some parts used even on cygwin.
! #if defined(_WIN32) || defined (__CYGWIN__)
  # include <windows.h>
  #endif
  
+ #ifdef __CYGWIN__
+ # undef _WIN32
+ extern "C" void cygwin_conv_to_win32_path(const char *path, char *win32_path);
+ #endif
+ 
  // getpwnam doesn't exist on Windows and Cray Xt3/Catamount
  // same for TIOCGWINSZ
***************
*** 893,929 ****
  }
  
! 
! // return true if the file exists
! bool SystemTools::FileExists(const char* filename, bool isFile)
  {
! #ifdef _MSC_VER
! # define access _access
! #endif
! #ifndef R_OK
! # define R_OK 04
  #endif
  
! #ifdef __SYLLABLE__
!   if ((filename !=0) && (*filename == 0))
      {
      return false;
!   }
  #endif
  
!   if ( access(filename, R_OK) != 0 )
      {
!     return false;
      }
    else
      {
!     // If isFile is set return not FileIsDirectory,
!     // so this will only be true if it is a file
!     if(isFile)
!       {
!       return !SystemTools::FileIsDirectory(filename);
!       }
!     return true;
      }
  }
  
  bool SystemTools::Touch(const char* filename, bool create)
--- 898,964 ----
  }
  
! //----------------------------------------------------------------------------
! #if defined(_WIN32) || defined(__CYGWIN__)
! static bool WindowsFileExists(const char* filename)
  {
!   WIN32_FILE_ATTRIBUTE_DATA fd;
!   return GetFileAttributesExA(filename, GetFileExInfoStandard, &fd) != 0;
! }
  #endif
  
! //----------------------------------------------------------------------------
! bool SystemTools::FileExists(const char* filename)
! {
!   if(!(filename && *filename))
      {
      return false;
!     }
! #if defined(__CYGWIN__)
!   // Convert filename to native windows path if possible.
!   char winpath[MAX_PATH];
!   if(SystemTools::PathCygwinToWin32(filename, winpath))
!     {
!     return WindowsFileExists(winpath);
!     }
!   return access(filename, R_OK) == 0;
! #elif defined(_WIN32)
!   return WindowsFileExists(filename);
! #else
!   return access(filename, R_OK) == 0;
  #endif
+ }
  
! //----------------------------------------------------------------------------
! bool SystemTools::FileExists(const char* filename, bool isFile)
! {
!   if(SystemTools::FileExists(filename))
      {
!     // If isFile is set return not FileIsDirectory,
!     // so this will only be true if it is a file
!     return !isFile || !SystemTools::FileIsDirectory(filename);
!     }
!   return false;
! }
! 
! //----------------------------------------------------------------------------
! #ifdef __CYGWIN__
! bool SystemTools::PathCygwinToWin32(const char *path, char *win32_path)
! {
!   SystemToolsTranslationMap::iterator i =
!     SystemTools::Cyg2Win32Map->find(path);
! 
!   if (i != SystemTools::Cyg2Win32Map->end())
!     {
!     strncpy(win32_path, i->second.c_str(), MAX_PATH);
      }
    else
      {
!     cygwin_conv_to_win32_path(path, win32_path);
!     SystemToolsTranslationMap::value_type entry(path, win32_path);
!     SystemTools::Cyg2Win32Map->insert(entry);
      }
+   return win32_path[0] != 0;
  }
+ #endif
  
  bool SystemTools::Touch(const char* filename, bool create)
***************
*** 4537,4540 ****
--- 4572,4578 ----
  SystemToolsTranslationMap *SystemTools::TranslationMap;
  SystemToolsTranslationMap *SystemTools::LongPathMap;
+ #ifdef __CYGWIN__
+ SystemToolsTranslationMap *SystemTools::Cyg2Win32Map;
+ #endif
  
  // SystemToolsManager manages the SystemTools singleton.
***************
*** 4582,4585 ****
--- 4620,4626 ----
    SystemTools::TranslationMap = new SystemToolsTranslationMap;
    SystemTools::LongPathMap = new SystemToolsTranslationMap;
+ #ifdef __CYGWIN__
+   SystemTools::Cyg2Win32Map = new SystemToolsTranslationMap;
+ #endif
  
    // Add some special translation paths for unix.  These are not added
***************
*** 4638,4641 ****
--- 4679,4685 ----
    delete SystemTools::TranslationMap;
    delete SystemTools::LongPathMap;
+ #ifdef __CYGWIN__
+   delete SystemTools::Cyg2Win32Map;
+ #endif
  }
  

Index: SystemTools.hxx.in
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/kwsys/SystemTools.hxx.in,v
retrieving revision 1.78
retrieving revision 1.79
diff -C 2 -d -r1.78 -r1.79
*** SystemTools.hxx.in	5 Jun 2009 16:01:29 -0000	1.78
--- SystemTools.hxx.in	22 Sep 2009 17:02:20 -0000	1.79
***************
*** 276,280 ****
     * if it is a file or a directory.
     */
!   static bool FileExists(const char* filename, bool isFile=false);
  
    /**
--- 276,290 ----
     * if it is a file or a directory.
     */
!   static bool FileExists(const char* filename, bool isFile);
!   static bool FileExists(const char* filename);
! 
!   /**
!    * Converts Cygwin path to Win32 path. Uses dictionary container for
!    * caching and calls to cygwin_conv_to_win32_path from Cygwin dll
!    * for actual translation.  Returns true on success, else false.
!    */
! #ifdef __CYGWIN__
!   static bool PathCygwinToWin32(const char *path, char *win32_path);
! #endif
  
    /**
***************
*** 891,894 ****
--- 901,907 ----
    static SystemToolsTranslationMap *TranslationMap;
    static SystemToolsTranslationMap *LongPathMap;
+ #ifdef __CYGWIN__
+   static SystemToolsTranslationMap *Cyg2Win32Map;
+ #endif
    friend class SystemToolsManager;
  };



More information about the Cmake-commits mailing list