1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Simplify the way position lists are copied when merging data.

FossilOrigin-Name: 9f8d678a0ea75e169daf8b3f00bd05f52a050ea6
This commit is contained in:
dan
2014-08-11 20:26:34 +00:00
parent c7fe7a969b
commit 1a669f84a1
3 changed files with 39 additions and 21 deletions

View File

@ -2813,6 +2813,34 @@ static void fts5WriteAppendPoslistInt(
}
}
static void fts5WriteAppendPoslistData(
Fts5Index *p,
Fts5SegWriter *pWriter,
const u8 *aData,
int nData
){
Fts5PageWriter *pPage = &pWriter->aWriter[0];
const u8 *a = aData;
int n = nData;
while( p->rc==SQLITE_OK && (pPage->buf.n + n)>=p->pgsz ){
int nReq = p->pgsz - pPage->buf.n;
int nCopy = 0;
while( nCopy<nReq ){
i64 dummy;
nCopy += getVarint(&a[nCopy], (u64*)&dummy);
}
fts5BufferAppendBlob(&p->rc, &pPage->buf, nCopy, a);
a += nCopy;
n -= nCopy;
fts5WriteFlushLeaf(p, pWriter);
pWriter->bFirstRowidInPage = 1;
}
if( n>0 ){
fts5BufferAppendBlob(&p->rc, &pPage->buf, n, a);
}
}
static void fts5WriteAppendZerobyte(Fts5Index *p, Fts5SegWriter *pWriter){
fts5BufferAppendVarint(&p->rc, &pWriter->aWriter[0].buf, 0);
}
@ -3041,12 +3069,7 @@ fflush(stdout);
/* Copy the position list from input to output */
fts5WriteAppendPoslistInt(p, &writer, sPos.nRem);
for(/* noop */; !fts5ChunkIterEof(p, &sPos); fts5ChunkIterNext(p, &sPos)){
int iOff = 0;
while( iOff<sPos.n ){
int iVal;
iOff += getVarint32(&sPos.p[iOff], iVal);
fts5WriteAppendPoslistInt(p, &writer, iVal);
}
fts5WriteAppendPoslistData(p, &writer, sPos.p, sPos.n);
}
}
@ -3180,9 +3203,9 @@ static int fts5FlushNewEntry(
const u8 *aPoslist,
int nPoslist
){
Fts5Buffer *pBuf;
Fts5FlushCtx *p = (Fts5FlushCtx*)pCtx;
int rc = SQLITE_OK;
int i = 0;
/* Append the rowid itself */
fts5WriteAppendRowid(p->pIdx, &p->writer, iRowid);
@ -3190,13 +3213,8 @@ static int fts5FlushNewEntry(
/* Append the size of the position list in bytes */
fts5WriteAppendPoslistInt(p->pIdx, &p->writer, nPoslist);
/* Copy the position list to the output segment */
while( i<nPoslist ){
int iVal;
i += getVarint32(&aPoslist[i], iVal);
fts5WriteAppendPoslistInt(p->pIdx, &p->writer, iVal);
}
/* And the poslist data */
fts5WriteAppendPoslistData(p->pIdx, &p->writer, aPoslist, nPoslist);
return rc;
}