]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Update some comments in vdbesort.c.
authordan <dan@noemail.net>
Thu, 26 Jul 2012 09:21:14 +0000 (09:21 +0000)
committerdan <dan@noemail.net>
Thu, 26 Jul 2012 09:21:14 +0000 (09:21 +0000)
FossilOrigin-Name: f4b3fded231231ef15bde98d2a996b4e16415d4c

manifest
manifest.uuid
src/vdbesort.c

index 8ee9b917a6875025e010909fb47d1df873e01885..c3c728bb31e7443472ed96c43211e35cb12d1d63 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\sedge\scase\sin\svdbesort.c.
-D 2012-07-23T20:10:35.296
+C Update\ssome\scomments\sin\svdbesort.c.
+D 2012-07-26T09:21:14.241
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 8f6d858bf3df9978ba43df19985146a1173025e4
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -244,7 +244,7 @@ F src/vdbeapi.c 88ea823bbcb4320f5a6607f39cd7c2d3cc4c26b1
 F src/vdbeaux.c dce80038c3c41f2680e5ab4dd0f7e0d8b7ff9071
 F src/vdbeblob.c 32f2a4899d67f69634ea4dd93e3f651936d732cb
 F src/vdbemem.c cb55e84b8e2c15704968ee05f0fae25883299b74
-F src/vdbesort.c bd37dbd4a023f75e9cd1eec18e171aa6f2552d20
+F src/vdbesort.c 106796cedf32a8209e92f28560d0523193c19a9a
 F src/vdbetrace.c 79059ebd17b3c8545fab2a24253713e77e4ab392
 F src/vtab.c bb8ea3a26608bb1357538a5d2fc72beba6638998
 F src/wal.c 9294df6f96aae5909ae1a9b733fd1e1b4736978b
@@ -1005,7 +1005,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
-P 55e47ef338c42f95f0f071d6ec92cd2480f9f1fe
-R c1d0187a30b4d8ec69c9c7f13c2ce356
+P 4ba266fc534f390267180eca8d68b8d5f0b7f832
+R e276763c29e00cdde695ab89ab0038a7
 U dan
-Z 60c5c030c4ed6dd425cd291cf7eefd27
+Z 42e5e7096761a49ccf3e633dc0ad5716
index 239b7c9706c69de6ca5ecd8e6d39039d132f2a60..528757c4ac7b6e51506db87078e01fce2fcd8a69 100644 (file)
@@ -1 +1 @@
-4ba266fc534f390267180eca8d68b8d5f0b7f832
\ No newline at end of file
+f4b3fded231231ef15bde98d2a996b4e16415d4c
\ No newline at end of file
index 7778196f1c2e41ecc94cbf637eb64f362f574ccf..c00e9a2f1a497796d05f8e9784987c81ab72614d 100644 (file)
@@ -180,51 +180,68 @@ static int vdbeSorterIterRead(
   int nByte,                      /* Bytes of data to read */
   u8 **ppOut                      /* OUT: Pointer to buffer containing data */
 ){
-  int iBuf;
-  int nAvail;
+  int iBuf;                       /* Offset within buffer to read from */
+  int nAvail;                     /* Bytes of data available in buffer */
   assert( p->aBuffer );
 
+  /* If there is no more data to be read from the buffer, read the next 
+  ** p->nBuffer bytes of data from the file into it. Or, if there are less
+  ** than p->nBuffer bytes remaining in the PMA, read all remaining data.  */
   iBuf = p->iReadOff % p->nBuffer;
   if( iBuf==0 ){
-    int nRead;
-    int rc;
+    int nRead;                    /* Bytes to read from disk */
+    int rc;                       /* sqlite3OsRead() return code */
 
+    /* Determine how many bytes of data to read. */
     nRead = p->iEof - p->iReadOff;
     if( nRead>p->nBuffer ) nRead = p->nBuffer;
     assert( nRead>0 );
+
+    /* Read data from the file. Return early if an error occurs. */
     rc = sqlite3OsRead(p->pFile, p->aBuffer, nRead, p->iReadOff);
     assert( rc!=SQLITE_IOERR_SHORT_READ );
     if( rc!=SQLITE_OK ) return rc;
   }
-  nAvail = p->nBuffer - iBuf;
+  nAvail = p->nBuffer - iBuf; 
 
   if( nByte<=nAvail ){
+    /* The requested data is available in the in-memory buffer. In this
+    ** case there is no need to make a copy of the data, just return a 
+    ** pointer into the buffer to the caller.  */
     *ppOut = &p->aBuffer[iBuf];
     p->iReadOff += nByte;
   }else{
-    int nRem;
+    /* The requested data is not all available in the in-memory buffer.
+    ** In this case, allocate space at p->aAlloc[] to copy the requested
+    ** range into. Then return a copy of pointer p->aAlloc to the caller.  */
+    int nRem;                     /* Bytes remaining to copy */
+
+    /* Extend the p->aAlloc[] allocation if required. */
     if( p->nAlloc<nByte ){
       int nNew = p->nAlloc*2;
       while( nByte>nNew ) nNew = nNew*2;
-
       p->aAlloc = sqlite3DbReallocOrFree(db, p->aAlloc, nNew);
       if( !p->aAlloc ) return SQLITE_NOMEM;
     }
 
+    /* Copy as much data as is available in the buffer into the start of
+    ** p->aAlloc[].  */
     memcpy(p->aAlloc, &p->aBuffer[iBuf], nAvail);
     p->iReadOff += nAvail;
     nRem = nByte - nAvail;
+
+    /* The following loop copies up to p->nBuffer bytes per iteration into
+    ** the p->aAlloc[] buffer.  */
     while( nRem>0 ){
-      int rc;
-      int nCopy;
-      u8 *aNext;
+      int rc;                     /* vdbeSorterIterRead() return code */
+      int nCopy;                  /* Number of bytes to copy */
+      u8 *aNext;                  /* Pointer to buffer to copy data from */
 
       nCopy = nRem;
       if( nRem>p->nBuffer ) nCopy = p->nBuffer;
       rc = vdbeSorterIterRead(db, p, nCopy, &aNext);
       if( rc!=SQLITE_OK ) return rc;
       assert( aNext!=p->aAlloc );
-
       memcpy(&p->aAlloc[nByte - nRem], aNext, nCopy);
       nRem -= nCopy;
     }