Opened 16 years ago

Last modified 12 years ago

#314 closed defect (fixed)

AVC speedup patch - - not so many file stat()s

Reported by: carl.anderson@… Owned by: Daniel Morissette
Priority: high Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords:
Cc: Markus Neteler

Description

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)


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;

Change History (3)

comment:1 Changed 16 years ago by warmerdam

Daniel, 


Could you apply this upstream and then we can migrate it into GDAL? 


comment:2 Changed 14 years ago by warmerdam

Carl,

I had kind of wanted to change look at using code to fetch the files in the
directory and do a case insensitive search against those rather than doing 
all this stat()ing, but I never got the time.  I have applied your changes 
upstream to Daniel's AVCE00 library in CVS. 

Thanks for the patch!

comment:3 Changed 12 years ago by Daniel Morissette

Marking fixed since the patch has been applied a while ago.

We will keep reading the directory and doing a case-insensitive search as an enahncement in the AVCE00 bugzilla at
http://bugzilla.maptools.org/show_bug.cgi?id=173
Note: See TracTickets for help on using tickets.