SQLITE_EXTENSION_INIT1
#endif
+/*
+** GCC does not define the offsetof() macro so we'll have to do it
+** ourselves. This definition was copied from sqlite3Int.h.
+*/
+#ifndef offsetof
+#define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
+#endif
+
static int fts3EvalNext(Fts3Cursor *pCsr);
static int fts3EvalStart(Fts3Cursor *pCsr);
static int fts3TermSegReaderCursor(
** Implementation of xOpen method.
*/
static int fts3OpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){
- sqlite3_vtab_cursor *pCsr; /* Allocated cursor */
-
- UNUSED_PARAMETER(pVTab);
+ Fts3Table *p = (Fts3Table *)pVTab;
+ Fts3Cursor *pCsr; /* Allocated cursor */
/* Allocate a buffer large enough for an Fts3Cursor structure. If the
** allocation succeeds, zero it and return SQLITE_OK. Otherwise,
** if the allocation fails, return SQLITE_NOMEM.
*/
- *ppCsr = pCsr = (sqlite3_vtab_cursor *)sqlite3_malloc(sizeof(Fts3Cursor));
+ pCsr = (Fts3Cursor*)sqlite3_malloc(sizeof(Fts3Cursor));
+ *ppCsr = (sqlite3_vtab_cursor*)pCsr;
if( !pCsr ){
return SQLITE_NOMEM;
}
memset(pCsr, 0, sizeof(Fts3Cursor));
+
+ /* Link the new cursor into the linked list at Fts3Table.pCsr. */
+ pCsr->pNext = p->pAllCsr;
+ p->pAllCsr = pCsr;
+ pCsr->iId = ++p->iLastCsrId;
+
return SQLITE_OK;
}
** argument.
*/
static void fts3ClearCursor(Fts3Cursor *pCsr){
+ const int nZero = sizeof(Fts3Cursor)-offsetof(Fts3Cursor,eSearch);
fts3CursorFinalizeStmt(pCsr);
sqlite3Fts3FreeDeferredTokens(pCsr);
sqlite3_free(pCsr->aDoclist);
sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
sqlite3Fts3ExprFree(pCsr->pExpr);
- memset(&(&pCsr->base)[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
+ memset((void*)&pCsr->eSearch, 0, nZero);
}
/*
** on the xClose method of the virtual table interface.
*/
static int fts3CloseMethod(sqlite3_vtab_cursor *pCursor){
- Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
- assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
+ Fts3Table *p = (Fts3Table*)pCursor->pVtab;
+ Fts3Cursor *pCsr = (Fts3Cursor*)pCursor;
+ Fts3Cursor **pp;
+ assert( p->pSegments==0 );
fts3ClearCursor(pCsr);
- assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
+ assert( p->pSegments==0 );
+ for(pp=&p->pAllCsr; (*pp)!=pCsr; pp=&(*pp)->pNext);
+ *pp = 0;
sqlite3_free(pCsr);
return SQLITE_OK;
}
switch( iCol-p->nColumn ){
case 0:
/* The special 'table-name' column */
- sqlite3_result_pointer(pCtx, pCsr);
+ sqlite3_result_int(pCtx, pCsr->iId);
break;
case 1:
sqlite3_value *pVal, /* argv[0] passed to function */
Fts3Cursor **ppCsr /* OUT: Store cursor handle here */
){
- int rc;
- *ppCsr = (Fts3Cursor*)sqlite3_value_pointer(pVal);
- if( (*ppCsr)!=0 ){
- rc = SQLITE_OK;
- }else{
+ int rc = SQLITE_OK;
+ int iId;
+ Fts3Table *p = (Fts3Table*)sqlite3_user_data(pContext);
+ iId = sqlite3_value_int(pVal);
+ Fts3Cursor *pRet;
+
+ for(pRet=p->pAllCsr; pRet; pRet=pRet->pNext){
+ if( pRet->iId==iId ) break;
+ }
+ *ppCsr = pRet;
+
+ if( pRet==0 ){
char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
sqlite3_result_error(pContext, zErr, -1);
sqlite3_free(zErr);
for(i=0; i<SizeofArray(aOverload); i++){
if( strcmp(zName, aOverload[i].zName)==0 ){
*pxFunc = aOverload[i].xFunc;
+ *ppArg = (void*)pVtab;
return 1;
}
}
-C Add\sthe\s"unionvtab"\svirtual\stable\sextension\sin\sext/misc/unionvtab.c.
-D 2017-07-15T20:48:30.280
+C Use\sinteger\shandles\sfor\sfts3\scursors\sfor\sa\ssmall\sperformance\simprovement.
+D 2017-07-17T09:30:15.939
F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 20850e3e8d4d4791e0531955852d768eb06f24138214870d543abb1a47346fba
F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a
F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314
F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
-F ext/fts3/fts3.c 02fbd2215309a7a73cbf29045897344987b6e17bb0b1685d13155f8b29768a50
+F ext/fts3/fts3.c 839018ad38355de1b6a36240d2b5c4fd32af617b8a8adbeb37239241fcece771
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
-F ext/fts3/fts3Int.h eb2502000148e80913b965db3e59f29251266d0a
+F ext/fts3/fts3Int.h 6e503a752e2cf8f4de312d8909a00d6df101c99f270de1861a1d6d0cbc038120
F ext/fts3/fts3_aux.c 9edc3655fcb287f0467d0a4b886a01c6185fe9f1
F ext/fts3/fts3_expr.c dfd571a24412779ac01f25c01d888c6ef7b2d0ef
F ext/fts3/fts3_hash.c 29b986e43f4e9dd40110eafa377dc0d63c422c60
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 253945d480b052bfe311888022b5eb0be91c8c80cda05036e58207d57520262c
-R ee0a9dc5b1464f766485894fa2069cae
+P 62a86aa6c0519cf1fa232169122d3d6ae8d2f66b20530fb934a82a15712bd2f0
+R 1f2a6820ac6b2ca14c452355885bac61
+T *branch * fts3-int-cursor
+T *sym-fts3-int-cursor *
+T -sym-trunk *
U dan
-Z d195e18cbc4e4f34f8cf4b9b0b0c8aaa
+Z 5522287dc73b8f3fd5c7ba004e151c88