]> git.sur5r.net Git - bacula/bacula/commitdiff
- add stringlength cache to improve comparison in Win32UTF8->UCS2 cache
authorThorsten Engel <thorsten.engel@matrix-computer.com>
Tue, 23 May 2006 12:01:07 +0000 (12:01 +0000)
committerThorsten Engel <thorsten.engel@matrix-computer.com>
Tue, 23 May 2006 12:01:07 +0000 (12:01 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3027 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/win32/compat/compat.cpp

index f1a172713ad43b935a902bfdbfda156ef2e7f742..a9f46a1173aa145577a0a10e18660e1fc20e576a 100644 (file)
@@ -45,8 +45,9 @@
    conversion is called 3 times (lstat, attribs, open),
    by using the cache this is reduced to 1 time */
 
-POOLMEM *g_pWin32ConvUTF8Cache = get_pool_memory (PM_FNAME);
-POOLMEM *g_pWin32ConvUCS2Cache = get_pool_memory (PM_FNAME);
+static POOLMEM *g_pWin32ConvUTF8Cache = get_pool_memory (PM_FNAME);
+static POOLMEM *g_pWin32ConvUCS2Cache = get_pool_memory (PM_FNAME);
+static DWORD g_dwWin32ConvUTF8strlen = 0;
 static pthread_mutex_t Win32Convmutex = PTHREAD_MUTEX_INITIALIZER;
 
 void Win32ConvCleanupCache()
@@ -60,6 +61,8 @@ void Win32ConvCleanupCache()
       free_pool_memory(g_pWin32ConvUCS2Cache);   
       g_pWin32ConvUCS2Cache = NULL;
    }
+
+   g_dwWin32ConvUTF8strlen = 0;
 }
 
 
@@ -373,13 +376,17 @@ int
 make_win32_path_UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF, BOOL* pBIsRawPath /*= NULL*/)
 {
    P(Win32Convmutex);
-   /* if we find the utf8 string in cache, we use the cached ucs2 version */
-   if (bstrcmp(pszUTF, g_pWin32ConvUTF8Cache)) {
-      int32_t nBufSize = sizeof_pool_memory(g_pWin32ConvUCS2Cache);
-      *pszUCS = check_pool_memory_size(*pszUCS, nBufSize);      
-      wcscpy((LPWSTR) *pszUCS, (LPWSTR) g_pWin32ConvUCS2Cache);
-      V(Win32Convmutex);
-      return nBufSize / sizeof (WCHAR);
+   /* if we find the utf8 string in cache, we use the cached ucs2 version.
+      we compare the stringlength first (quick check) and then compare the content.            
+   */
+   if (g_dwWin32ConvUTF8strlen == strlen(pszUTF)) {
+      if (bstrcmp(pszUTF, g_pWin32ConvUTF8Cache)) {
+         int32_t nBufSize = sizeof_pool_memory(g_pWin32ConvUCS2Cache);
+         *pszUCS = check_pool_memory_size(*pszUCS, nBufSize);      
+         wcscpy((LPWSTR) *pszUCS, (LPWSTR) g_pWin32ConvUCS2Cache);
+         V(Win32Convmutex);
+         return nBufSize / sizeof (WCHAR);
+      }
    }
 
    /* helper to convert from utf-8 to UCS-2 and to complete a path for 32K path syntax */
@@ -393,13 +400,13 @@ make_win32_path_UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF, BOOL* pBIsRaw
       *pBIsRawPath = FALSE;
 #endif
 
-   /* populate cache */   
-   int32_t nBufSize = sizeof_pool_memory(*pszUCS);
-   g_pWin32ConvUCS2Cache = check_pool_memory_size(g_pWin32ConvUCS2Cache, nBufSize);
+   /* populate cache */      
+   g_pWin32ConvUCS2Cache = check_pool_memory_size(g_pWin32ConvUCS2Cache, sizeof_pool_memory(*pszUCS));
    wcscpy((LPWSTR) g_pWin32ConvUCS2Cache, (LPWSTR) *pszUCS);
-   nBufSize = strlen(pszUTF)+1;
-   g_pWin32ConvUTF8Cache = check_pool_memory_size(g_pWin32ConvUTF8Cache, nBufSize);
-   bstrncpy(g_pWin32ConvUTF8Cache, pszUTF, nBufSize);
+   
+   g_dwWin32ConvUTF8strlen = strlen(pszUTF);
+   g_pWin32ConvUTF8Cache = check_pool_memory_size(g_pWin32ConvUTF8Cache, g_dwWin32ConvUTF8strlen+1);
+   bstrncpy(g_pWin32ConvUTF8Cache, pszUTF, g_dwWin32ConvUTF8strlen+1);
    V(Win32Convmutex);
 
    return nRet;