]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Remove some more code from fts5_index.c by consolidating similar functions.
authordan <dan@noemail.net>
Thu, 3 Sep 2015 14:22:27 +0000 (14:22 +0000)
committerdan <dan@noemail.net>
Thu, 3 Sep 2015 14:22:27 +0000 (14:22 +0000)
FossilOrigin-Name: 59ae30b97b40faa363c55aa2664dead9eaeeddc0

ext/fts5/fts5Int.h
ext/fts5/fts5_index.c
ext/fts5/fts5_storage.c
manifest
manifest.uuid

index 1da017fb011c56c371dd7dea29219990f2d56529..837ecb1ccdc414e23553bbd10a28e91041248173 100644 (file)
@@ -384,9 +384,9 @@ int sqlite3Fts5IndexErrcode(Fts5Index*);
 void sqlite3Fts5IndexReset(Fts5Index*);
 
 /*
-** Get or set the "averages" record.
+** Get or set the "averages" values.
 */
-int sqlite3Fts5IndexGetAverages(Fts5Index *p, Fts5Buffer *pBuf);
+int sqlite3Fts5IndexGetAverages(Fts5Index *p, i64 *pnRow, i64 *anSize);
 int sqlite3Fts5IndexSetAverages(Fts5Index *p, const u8*, int);
 
 /*
index 06a5d56bbc551407c9c73ec2a015e807913ebe99..7bb744773ccf75bb73cf753f3d3fba5b57b21fc0 100644 (file)
@@ -554,23 +554,6 @@ struct Fts5DlidxIter {
   Fts5DlidxLvl aLvl[1];
 };
 
-
-
-/*
-** The first argument passed to this macro is a pointer to an Fts5Buffer
-** object.
-*/
-#define fts5BufferSize(pBuf,n) {                \
-  if( pBuf->nSpace<n ) {                        \
-    u8 *pNew = sqlite3_realloc(pBuf->p, n);     \
-    if( pNew==0 ){                              \
-      sqlite3_free(pBuf->p);                    \
-    }                                           \
-    pBuf->nSpace = n;                           \
-    pBuf->p = pNew;                             \
-  }                                             \
-}
-
 static void fts5PutU16(u8 *aOut, u16 iVal){
   aOut[0] = (iVal>>8);
   aOut[1] = (iVal&0xFF);
@@ -647,11 +630,14 @@ static void fts5CloseReader(Fts5Index *p){
   }
 }
 
-static Fts5Data *fts5DataReadOrBuffer(
-  Fts5Index *p, 
-  Fts5Buffer *pBuf, 
-  i64 iRowid
-){
+
+/*
+** Retrieve a record from the %_data table.
+**
+** If an error occurs, NULL is returned and an error left in the 
+** Fts5Index object.
+*/
+static Fts5Data *fts5DataRead(Fts5Index *p, i64 iRowid){
   Fts5Data *pRet = 0;
   if( p->rc==SQLITE_OK ){
     int rc = SQLITE_OK;
@@ -671,8 +657,8 @@ static Fts5Data *fts5DataReadOrBuffer(
       if( rc==SQLITE_ABORT ) rc = SQLITE_OK;
     }
 
-    /* If the blob handle is not yet open, open and seek it. Otherwise, use
-    ** the blob_reopen() API to reseek the existing blob handle.  */
+    /* If the blob handle is not open at this point, open it and seek 
+    ** to the requested entry.  */
     if( p->pReader==0 && rc==SQLITE_OK ){
       Fts5Config *pConfig = p->pConfig;
       rc = sqlite3_blob_open(pConfig->db, 
@@ -690,22 +676,13 @@ static Fts5Data *fts5DataReadOrBuffer(
     if( rc==SQLITE_OK ){
       u8 *aOut = 0;               /* Read blob data into this buffer */
       int nByte = sqlite3_blob_bytes(p->pReader);
-      if( pBuf ){
-        fts5BufferSize(pBuf, MAX(nByte, p->pConfig->pgsz) + 20);
-        pBuf->n = nByte;
-        aOut = pBuf->p;
-        if( aOut==0 ){
-          rc = SQLITE_NOMEM;
-        }
+      int nAlloc = sizeof(Fts5Data) + nByte + FTS5_DATA_PADDING;
+      pRet = (Fts5Data*)sqlite3_malloc(nAlloc);
+      if( pRet ){
+        pRet->n = nByte;
+        aOut = pRet->p = (u8*)&pRet[1];
       }else{
-        int nSpace = nByte + FTS5_DATA_PADDING;
-        pRet = (Fts5Data*)sqlite3_malloc(nSpace+sizeof(Fts5Data));
-        if( pRet ){
-          pRet->n = nByte;
-          aOut = pRet->p = (u8*)&pRet[1];
-        }else{
-          rc = SQLITE_NOMEM;
-        }
+        rc = SQLITE_NOMEM;
       }
 
       if( rc==SQLITE_OK ){
@@ -720,33 +697,10 @@ static Fts5Data *fts5DataReadOrBuffer(
     p->nRead++;
   }
 
-  return pRet;
-}
-
-/*
-** Retrieve a record from the %_data table.
-**
-** If an error occurs, NULL is returned and an error left in the 
-** Fts5Index object.
-*/
-static Fts5Data *fts5DataRead(Fts5Index *p, i64 iRowid){
-  Fts5Data *pRet = fts5DataReadOrBuffer(p, 0, iRowid);
   assert( (pRet==0)==(p->rc!=SQLITE_OK) );
   return pRet;
 }
 
-/*
-** Read a record from the %_data table into the buffer supplied as the
-** second argument.
-**
-** If an error occurs, an error is left in the Fts5Index object. If an
-** error has already occurred when this function is called, it is a 
-** no-op.
-*/
-static void fts5DataBuffer(Fts5Index *p, Fts5Buffer *pBuf, i64 iRowid){
-  (void)fts5DataReadOrBuffer(p, pBuf, iRowid);
-}
-
 /*
 ** Release a reference to data record returned by an earlier call to
 ** fts5DataRead().
@@ -1015,19 +969,18 @@ static Fts5Structure *fts5StructureRead(Fts5Index *p){
   Fts5Config *pConfig = p->pConfig;
   Fts5Structure *pRet = 0;        /* Object to return */
   int iCookie;                    /* Configuration cookie */
+  Fts5Data *pData;
   Fts5Buffer buf = {0, 0, 0};
 
-  fts5DataBuffer(p, &buf, FTS5_STRUCTURE_ROWID);
-  if( buf.p==0 ) return 0;
-  assert( buf.nSpace>=(buf.n + FTS5_DATA_ZERO_PADDING) );
-  memset(&buf.p[buf.n], 0, FTS5_DATA_ZERO_PADDING);
-  p->rc = fts5StructureDecode(buf.p, buf.n, &iCookie, &pRet);
-
+  pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID);
+  if( p->rc ) return 0;
+  memset(&pData->p[pData->n], 0, FTS5_DATA_PADDING);
+  p->rc = fts5StructureDecode(pData->p, pData->n, &iCookie, &pRet);
   if( p->rc==SQLITE_OK && pConfig->iCookie!=iCookie ){
     p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
   }
 
-  fts5BufferFree(&buf);
+  fts5DataRelease(pData);
   if( p->rc!=SQLITE_OK ){
     fts5StructureRelease(pRet);
     pRet = 0;
@@ -2490,13 +2443,13 @@ static void fts5SegIterNextFrom(
     }
   }
 
-  while( p->rc==SQLITE_OK ){
+  do{
     if( bMove ) fts5SegIterNext(p, pIter, 0);
     if( pIter->pLeaf==0 ) break;
     if( bRev==0 && pIter->iRowid>=iMatch ) break;
     if( bRev!=0 && pIter->iRowid<=iMatch ) break;
     bMove = 1;
-  }
+  }while( p->rc==SQLITE_OK );
 }
 
 
@@ -4272,13 +4225,9 @@ int sqlite3Fts5IndexRollback(Fts5Index *p){
 */
 int sqlite3Fts5IndexReinit(Fts5Index *p){
   Fts5Structure s;
-
-  assert( p->rc==SQLITE_OK );
-  p->rc = sqlite3Fts5IndexSetAverages(p, (const u8*)"", 0);
-
   memset(&s, 0, sizeof(Fts5Structure));
+  fts5DataWrite(p, FTS5_AVERAGES_ROWID, (const u8*)"", 0);
   fts5StructureWrite(p, &s);
-
   return fts5IndexReturn(p);
 }
 
@@ -4600,13 +4549,28 @@ void sqlite3Fts5IterClose(Fts5IndexIter *pIter){
 }
 
 /*
-** Read the "averages" record into the buffer supplied as the second 
-** argument. Return SQLITE_OK if successful, or an SQLite error code
-** if an error occurs.
+** Read and decode the "averages" record from the database. 
+**
+** Parameter anSize must point to an array of size nCol, where nCol is
+** the number of user defined columns in the FTS table.
 */
-int sqlite3Fts5IndexGetAverages(Fts5Index *p, Fts5Buffer *pBuf){
-  assert( p->rc==SQLITE_OK );
-  fts5DataReadOrBuffer(p, pBuf, FTS5_AVERAGES_ROWID);
+int sqlite3Fts5IndexGetAverages(Fts5Index *p, i64 *pnRow, i64 *anSize){
+  int nCol = p->pConfig->nCol;
+  Fts5Data *pData;
+
+  *pnRow = 0;
+  memset(anSize, 0, sizeof(i64) * nCol);
+  pData = fts5DataRead(p, FTS5_AVERAGES_ROWID);
+  if( p->rc==SQLITE_OK && pData->n ){
+    int i = 0;
+    int iCol;
+    i += fts5GetVarint(&pData->p[i], (u64*)pnRow);
+    for(iCol=0; i<pData->n && iCol<nCol; iCol++){
+      i += fts5GetVarint(&pData->p[i], (u64*)&anSize[iCol]);
+    }
+  }
+
+  fts5DataRelease(pData);
   return fts5IndexReturn(p);
 }
 
index c91e7eeba3498ad601132446c028dc568dfdf19c..65c6d48a36c600432fb8046eb4b0bec356e5dde6 100644 (file)
@@ -455,22 +455,7 @@ static int fts5StorageInsertDocsize(
 static int fts5StorageLoadTotals(Fts5Storage *p, int bCache){
   int rc = SQLITE_OK;
   if( p->bTotalsValid==0 ){
-    int nCol = p->pConfig->nCol;
-    Fts5Buffer buf;
-    memset(&buf, 0, sizeof(buf));
-
-    memset(p->aTotalSize, 0, sizeof(i64) * nCol);
-    p->nTotalRow = 0;
-    rc = sqlite3Fts5IndexGetAverages(p->pIndex, &buf);
-    if( rc==SQLITE_OK && buf.n ){
-      int i = 0;
-      int iCol;
-      i += fts5GetVarint(&buf.p[i], (u64*)&p->nTotalRow);
-      for(iCol=0; i<buf.n && iCol<nCol; iCol++){
-        i += fts5GetVarint(&buf.p[i], (u64*)&p->aTotalSize[iCol]);
-      }
-    }
-    sqlite3_free(buf.p);
+    rc = sqlite3Fts5IndexGetAverages(p->pIndex, &p->nTotalRow, p->aTotalSize);
     p->bTotalsValid = bCache;
   }
   return rc;
index 73cbe4ee86aec7d1cf0caa546e833f1285fbaa5b..0e7dfca7b2c1aea8c33118057dcde645b19e0f45 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\sdead\scode\sfrom\sfts5_index.c.
-D 2015-09-03T11:17:52.904
+C Remove\ssome\smore\scode\sfrom\sfts5_index.c\sby\sconsolidating\ssimilar\sfunctions.
+D 2015-09-03T14:22:27.810
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in e2218eb228374422969de7b1680eda6864affcef
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -106,15 +106,15 @@ F ext/fts3/unicode/mkunicode.tcl 95cf7ec186e48d4985e433ff8a1c89090a774252
 F ext/fts3/unicode/parseunicode.tcl da577d1384810fb4e2b209bf3313074353193e95
 F ext/fts5/extract_api_docs.tcl 06583c935f89075ea0b32f85efa5dd7619fcbd03
 F ext/fts5/fts5.h 0784692f406588e6c90e13a78e1f36e7e3236e42
-F ext/fts5/fts5Int.h c6f035091fc9fa12a92c7066bf0c266c08cb508b
+F ext/fts5/fts5Int.h f65d41f66accad0a289d6bd66b13c07d2932f9be
 F ext/fts5/fts5_aux.c 7a307760a9c57c750d043188ec0bad59f5b5ec7e
 F ext/fts5/fts5_buffer.c 80f9ba4431848cb857e3d2158f5280093dcd8015
 F ext/fts5/fts5_config.c 80b61fd2c6844b64a3e72a64572d50a812da9384
 F ext/fts5/fts5_expr.c 0c36c1db8eccdeb006e3c8d1499d05015f6e11a6
 F ext/fts5/fts5_hash.c 4bf4b99708848357b8a2b5819e509eb6d3df9246
-F ext/fts5/fts5_index.c df98f39c0f6e9d06e144dde5a0751ab14ee9d0fd
+F ext/fts5/fts5_index.c febb68173333ae3248eb15928a18b21112d45135
 F ext/fts5/fts5_main.c e9d0892424bb7f0a8b58613d4ff75cb650cf286e
-F ext/fts5/fts5_storage.c 4b883f592ffdc6bcefba6fa03580228379a1333f
+F ext/fts5/fts5_storage.c 120f7b143688b5b7710dacbd48cff211609b8059
 F ext/fts5/fts5_tcl.c 6da58d6e8f42a93c4486b5ba9b187a7f995dee37
 F ext/fts5/fts5_test_mi.c e96be827aa8f571031e65e481251dc1981d608bf
 F ext/fts5/fts5_tokenize.c f380f46f341af9c9a9908e1aade685ba1eaa157a
@@ -1382,7 +1382,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 11b887b15eaee57ea2577c763e70494f1e251275
-R 97c9a99cb5cabc51c42bc2a29210372f
+P 8a0a9b01e74072ee52fe393311ad591208fbbf7c
+R e26c002d3fbf39ced0ec480a25b8c1b8
 U dan
-Z 9499a3a8b1a7472d387dbda943ee05af
+Z cd2601a80f5a8baa4e1506c2cddafc82
index f57a7a34cbea3b5b452b617f16e661f3b29ab795..03cc15587f5c1fa3fd146e11e4d3b81059cc28b7 100644 (file)
@@ -1 +1 @@
-8a0a9b01e74072ee52fe393311ad591208fbbf7c
\ No newline at end of file
+59ae30b97b40faa363c55aa2664dead9eaeeddc0
\ No newline at end of file