[Gdal-dev] AVC speedup patch

Carl Anderson carl.anderson at vadose.org
Mon Apr 7 11:13:07 EDT 2003


The included patch speeds up the ogr/orgsf_formats/avc backend format

The curent behavior is to try a file stat() on the upper and lower case
for each letter of the file path of the coverage.  That is a lot of
file stat()s.  In many cases the entire file is either all lower case
(Arc/Info in Solaris) or all upper case.

This patch tries these two common cases before trying all the other
permutations.

It speeds up an AvcReadOpenfile from 98 seconds to 1 second.
(Arc/Info Solaris Workspace with 1500 coverages)


I have backported to the avce00 lib if anyone desires.

cut here
------------------------------------------------------

diff -ur gdal/ogr/ogrsf_frmts/avc/avc_misc.c
gdal_new/ogr/ogrsf_frmts/avc/avc_misc.c
--- gdal/ogr/ogrsf_frmts/avc/avc_misc.c Thu Feb 14 09:37:21 2002
+++ gdal_new/ogr/ogrsf_frmts/avc/avc_misc.c     Sat Apr  5 14:27:51 2003
@@ -261,12 +261,45 @@
           return pszFname;
       }
    +    pszTmpPath = CPLStrdup(pszFname);
+    nTotalLen = strlen(pszTmpPath);
+
+    /*-----------------------------------------------------------------
+     * Try all lower case, check if the filename is OK as that.
+
*----------------------------------------------------------------*/
+    for (iTmpPtr=0; iTmpPtr< nTotalLen; iTmpPtr++)
+    {
+      if ( pszTmpPath[iTmpPtr] >= 0x41 && pszTmpPath[iTmpPtr] <= 0x5a )
+         pszTmpPath[iTmpPtr] += 32;
+    }
+
+    if (VSIStat(pszTmpPath, &sStatBuf) == 0)
+    {
+        strcpy(pszFname, pszTmpPath);
+        CPLFree(pszTmpPath);
+        return pszFname;
+    }
+
+    /*-----------------------------------------------------------------
+     * Try all upper case, check if the filename is OK as that.
+
*----------------------------------------------------------------*/
+    for (iTmpPtr=0; iTmpPtr< nTotalLen; iTmpPtr++)
+    {
+      if ( pszTmpPath[iTmpPtr] >= 0x61 && pszTmpPath[iTmpPtr] <= 0x7a )
+         pszTmpPath[iTmpPtr] -= 32;
+    }
+
+    if (VSIStat(pszTmpPath, &sStatBuf) == 0)
+    {
+        strcpy(pszFname, pszTmpPath);
+        CPLFree(pszTmpPath);
+        return pszFname;
+    }
+

/*-----------------------------------------------------------------
        * OK, file either does not exist or has the wrong cases... we'll
        * go backwards until we find a portion of the path that is 
valid.

*----------------------------------------------------------------*/
-    pszTmpPath = CPLStrdup(pszFname);
-    nTotalLen = strlen(pszTmpPath);
       iTmpPtr = nTotalLen;
       bValidPath = FALSE;



More information about the Gdal-dev mailing list