From 5dff5aa0af0497c8476912c6d2c9b9f9c5c735e5 Mon Sep 17 00:00:00 2001 From: bluhuang Date: Thu, 9 Jan 2025 16:20:36 +0800 Subject: [PATCH] optimize icu enable config Signed-off-by: bluhuang --- include/sqlite3.h | 2 +- src/sqlite3.c | 29 ++++++++++------------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/include/sqlite3.h b/include/sqlite3.h index 4e24bca..7d60b19 100644 --- a/include/sqlite3.h +++ b/include/sqlite3.h @@ -608,6 +608,7 @@ SQLITE_API int sqlite3_exec( #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ +#define SQLITE_OPEN_ICU_ENABLE 0x00100000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ @@ -2167,7 +2168,6 @@ struct sqlite3_mem_methods { #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ #define SQLITE_CONFIG_CORRUPTION 30 /* xCorruption */ -#define SQLITE_CONFIG_ENABLE_ICU 31 /* boolean */ /* ** CAPI3REF: Database Connection Configuration Options diff --git a/src/sqlite3.c b/src/sqlite3.c index 4c27691..6f0b27d 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -919,6 +919,7 @@ SQLITE_API int sqlite3_exec( #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ +#define SQLITE_OPEN_ICU_ENABLE 0x00100000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ @@ -2478,7 +2479,6 @@ struct sqlite3_mem_methods { #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ #define SQLITE_CONFIG_CORRUPTION 30 /* xCorruption */ -#define SQLITE_CONFIG_ENABLE_ICU 31 /* boolean */ /* ** CAPI3REF: Database Connection Configuration Options @@ -17195,6 +17195,9 @@ struct sqlite3 { #if defined(SQLITE_HAS_CODEC) && defined(SQLITE_CODEC_ATTACH_CHANGED) CodecParameter codecParm; #endif +#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) + u32 icuEnable; +#endif }; /* @@ -174035,7 +174038,6 @@ typedef void (*sqlite3Fts3IcuTokenizerModule_ptr)(sqlite3_tokenizer_module const typedef int (*sqlite3IcuInit_ptr)(sqlite3 *db); static sqlite3Fts3IcuTokenizerModule_ptr tokenModulePtr = NULL; static sqlite3IcuInit_ptr icuInitPtr = NULL; -static u32 icuEnable = 0u; static u32 icuInit = 0u; static void *g_library = NULL; @@ -174063,7 +174065,7 @@ int sqlite3IcuModuleInit(){ SQLITE_PRIVATE int sqlite3IcuInitInner(sqlite3 *db) { - if( !icuEnable ){ + if( !db->icuEnable ){ return SQLITE_OK; } return icuInitPtr(db); @@ -174476,18 +174478,6 @@ SQLITE_API int sqlite3_config(int op, ...){ int rc = SQLITE_OK; va_start(ap, op); -#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) - if( op==SQLITE_CONFIG_ENABLE_ICU ){ - int iVal = va_arg(ap, int); - if( iVal==0 ){ - icuEnable = 0u; - }else{ - icuEnable = 1u; - } - return rc; - } -#endif /* SQLITE_ENABLE_ICU */ - /* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while ** the SQLite library is in use. */ if( sqlite3GlobalConfig.isInit ) return SQLITE_MISUSE_BKPT; @@ -177563,9 +177553,10 @@ static int openDatabase( rc = sqlite3_errcode(db); #if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) - if( icuEnable ){ + db->icuEnable = flags & SQLITE_OPEN_ICU_ENABLE; + if (db->icuEnable) { rc = sqlite3IcuModuleInit(); - if( rc!=SQLITE_OK ) return rc; + if( rc!=SQLITE_OK ) return rc; } #endif @@ -184267,7 +184258,7 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){ #ifdef SQLITE_ENABLE_ICU const sqlite3_tokenizer_module *pIcu = 0; - if( icuEnable ){ + if( db->icuEnable ){ if( tokenModulePtr!=NULL ){ tokenModulePtr(&pIcu); }else{ @@ -184310,7 +184301,7 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){ || sqlite3Fts3HashInsert(&pHash->hash, "unicode61", 10, (void *)pUnicode) #endif #ifdef SQLITE_ENABLE_ICU - || (icuEnable && pIcu && sqlite3Fts3HashInsert(&pHash->hash, "icu", 4, (void *)pIcu)) + || (db->icuEnable && pIcu && sqlite3Fts3HashInsert(&pHash->hash, "icu", 4, (void *)pIcu)) #endif ){ rc = SQLITE_NOMEM; -- Gitee