Change the PRAGMA parser to use a binary search for the pragma name.

Also:  Minor performance enhancement to sqlite3DbFree() and to the
token dequoter.

FossilOrigin-Name: 870c030b4e1854e6e0d39907fadbd82774c16f56
This commit is contained in:
drh 2013-09-13 16:36:46 +00:00
parent f1d2670d40
commit 9ccd8659ff
6 changed files with 768 additions and 226 deletions

View File

@ -1,5 +1,5 @@
C Add\stests\sfor\sthe\sfts4\sunicode61\stokenchars\sand\sseparators\soptions.
D 2013-09-13T12:10:09.872
C Change\sthe\sPRAGMA\sparser\sto\suse\sa\sbinary\ssearch\sfor\sthe\spragma\sname.\nAlso:\s\sMinor\sperformance\senhancement\sto\ssqlite3DbFree()\sand\sto\sthe\ntoken\sdequoter.
D 2013-09-13T16:36:46.969
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -186,7 +186,7 @@ F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12
F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303
F src/main.c 35931467ec026b05babb279cb8a573e62f6fe1a3
F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6
F src/malloc.c 543a8eb5508eaf4cadf55a9b503379eba2088128
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa
F src/mem2.c dce31758da87ec2cfa52ba4c5df1aed6e07d8e8f
@ -210,7 +210,7 @@ F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f
F src/pcache.c f8043b433a57aba85384a531e3937a804432a346
F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222
F src/pcache1.c a467393909a4ed7ca9de066d85ba5c5b04a5be63
F src/pragma.c 3aa3d8c8623b7b71c5b1bfb72dcc31fb0c25665f
F src/pragma.c 49612a5c35fe0139a4b2e5fb0b7ee74d8a3a42b9
F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f
F src/printf.c da9119eb31a187a4b99f60aa4a225141c0ebb74b
F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68
@ -275,7 +275,7 @@ F src/tokenize.c 70061085a51f2f4fc15ece94f32c03bcb78e63b2
F src/trigger.c 5c0ea9b8755e7c5e1a700f3e27ac4f8d92dd221e
F src/update.c f5182157f5d0d0a97bc5f5e3c9bdba0dfbe08f08
F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
F src/util.c f566b5138099a2df8533b190d0dcc74b7dfbe0c9
F src/util.c 7f3e35432d6888d1e770c488c35bd98970c44eec
F src/vacuum.c d9c5759f4c5a438bb43c2086f72c5d2edabc36c8
F src/vdbe.c a393a94c0d77b86c7c4ad2cfb43ec4ba278d9596
F src/vdbe.h 4f554b5627f26710c4c36d919110a3fc611ca5c4
@ -1080,6 +1080,7 @@ F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc
F tool/mkautoconfamal.sh f8d8dbf7d62f409ebed5134998bf5b51d7266383
F tool/mkkeywordhash.c bb52064aa614e1426445e4b2b9b00eeecd23cc79
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e
F tool/mkpragmatab.tcl b45b0770c9be2b693911d19adc6056c6d9c9276b
F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
F tool/mksqlite3c-noext.tcl 8bce31074e4cbe631bb7676526a048335f4c9f02
F tool/mksqlite3c.tcl d344cc3144a0271cd853c5e3df36e9f31d78d619
@ -1112,7 +1113,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P 73634ca463f46027bfa8ea23f18abaa530460e24
R 4220c723ebfba5175f5b35a4f736cee8
U dan
Z ceac464bf6cfcc5f50757139a5d63046
P 9ce6f40dfb54b35cecba3cc9c1ec0d111f6e9f11
R eb0f561b34214cdc0ff256f03a4cb3be
U drh
Z 21cd5712344a4e80033620b1f645dca4

View File

@ -1 +1 @@
9ce6f40dfb54b35cecba3cc9c1ec0d111f6e9f11
870c030b4e1854e6e0d39907fadbd82774c16f56

View File

@ -484,6 +484,7 @@ void sqlite3_free(void *p){
*/
void sqlite3DbFree(sqlite3 *db, void *p){
assert( db==0 || sqlite3_mutex_held(db->mutex) );
if( p==0 ) return;
if( db ){
if( db->pnBytesFreed ){
*db->pnBytesFreed += sqlite3DbMallocSize(db, p);

File diff suppressed because it is too large Load Diff

View File

@ -193,7 +193,8 @@ int sqlite3Dequote(char *z){
case '[': quote = ']'; break; /* For MS SqlServer compatibility */
default: return -1;
}
for(i=1, j=0; ALWAYS(z[i]); i++){
for(i=1, j=0;; i++){
assert( z[i] );
if( z[i]==quote ){
if( z[i+1]==quote ){
z[j++] = quote;

335
tool/mkpragmatab.tcl Normal file
View File

@ -0,0 +1,335 @@
#!/usr/bin/tclsh
#
# Run this script to generate the pragma name lookup table C code.
#
# To add new pragmas, first add the name and other relevant attributes
# of the pragma to the "pragma_def" object below. Then run this script
# to generate the C-code for the lookup table and copy/paste the output
# of this script into the appropriate spot in the pragma.c source file.
# Then add the extra "case PragTyp_XXXXX:" and subsequent code for the
# new pragma.
#
set pragma_def {
NAME: full_column_names
TYPE: FLAG
ARG: SQLITE_FullColNames
NAME: short_column_names
TYPE: FLAG
ARG: SQLITE_ShortColNames
NAME: count_changes
TYPE: FLAG
ARG: SQLITE_CountRows
NAME: empty_result_callbacks
TYPE: FLAG
ARG: SQLITE_NullCallback
NAME: legacy_file_format
TYPE: FLAG
ARG: SQLITE_LegacyFileFmt
NAME: fullfsync
TYPE: FLAG
ARG: SQLITE_FullFSync
NAME: checkpoint_fullfsync
TYPE: FLAG
ARG: SQLITE_CkptFullFSync
NAME: cache_spill
TYPE: FLAG
ARG: SQLITE_CacheSpill
NAME: reverse_unordered_selects
TYPE: FLAG
ARG: SQLITE_ReverseOrder
NAME: query_only
TYPE: FLAG
ARG: SQLITE_QueryOnly
NAME: automatic_index
TYPE: FLAG
ARG: SQLITE_AutoIndex
IF: !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
NAME: sql_trace
TYPE: FLAG
ARG: SQLITE_SqlTrace
IF: defined(SQLITE_DEBUG)
NAME: vdbe_listing
TYPE: FLAG
ARG: SQLITE_VdbeListing
IF: defined(SQLITE_DEBUG)
NAME: vdbe_trace
TYPE: FLAG
ARG: SQLITE_VdbeTrace
IF: defined(SQLITE_DEBUG)
NAME: vdbe_addoptrace
TYPE: FLAG
ARG: SQLITE_VdbeAddopTrace
IF: defined(SQLITE_DEBUG)
NAME: vdbe_debug
TYPE: FLAG
ARG: SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace
IF: defined(SQLITE_DEBUG)
NAME: ignore_check_constraints
TYPE: FLAG
ARG: SQLITE_IgnoreChecks
IF: !defined(SQLITE_OMIT_CHECK)
NAME: writable_schema
TYPE: FLAG
ARG: SQLITE_WriteSchema|SQLITE_RecoveryMode
NAME: read_uncommitted
TYPE: FLAG
ARG: SQLITE_ReadUncommitted
NAME: recursive_triggers
TYPE: FLAG
ARG: SQLITE_RecTriggers
NAME: foreign_keys
TYPE: FLAG
ARG: SQLITE_ForeignKeys
IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
NAME: defer_foreign_keys
TYPE: FLAG
ARG: SQLITE_DeferFKs
IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
NAME: default_cache_size
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
NAME: page_size
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: secure_delete
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: page_count
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: max_page_count
TYPE: PAGE_COUNT
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: locking_mode
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: journal_mode
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: journal_size_limit
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: cache_size
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: mmap_size
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: auto_vacuum
IF: !defined(SQLITE_OMIT_AUTOVACUUM)
NAME: incremental_vacuum
IF: !defined(SQLITE_OMIT_AUTOVACUUM)
NAME: temp_store
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: temp_store_directory
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: data_store_directory
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
NAME: lock_proxy_file
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
NAME: synchronous
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
NAME: table_info
IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
NAME: index_info
IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
NAME: index_list
IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
NAME: database_list
IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
NAME: collation_list
IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
NAME: foreign_key_list
IF: !defined(SQLITE_OMIT_FOREIGN_KEY)
NAME: foreign_key_check
IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
NAME: parser_trace
IF: defined(SQLITE_DEBUG)
NAME: case_sensitive_like
NAME: integrity_check
IF: !defined(SQLITE_OMIT_INTEGRITY_CHECK)
NAME: quick_check
TYPE: INTEGRITY_CHECK
IF: !defined(SQLITE_OMIT_INTEGRITY_CHECK)
NAME: encoding
IF: !defined(SQLITE_OMIT_UTF16)
NAME: schema_version
TYPE: HEADER_VALUE
IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
NAME: user_version
TYPE: HEADER_VALUE
IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
NAME: freelist_count
TYPE: HEADER_VALUE
IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
NAME: application_id
TYPE: HEADER_VALUE
IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
NAME: compile_options
IF: !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
NAME: wal_checkpoint
IF: !defined(SQLITE_OMIT_WAL)
NAME: wal_autocheckpoint
IF: !defined(SQLITE_OMIT_WAL)
NAME: shrink_memory
NAME: busy_timeout
NAME: lock_status
IF: defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
NAME: key
IF: defined(SQLITE_HAS_CODEC)
NAME: rekey
IF: defined(SQLITE_HAS_CODEC)
NAME: hexkey
IF: defined(SQLITE_HAS_CODEC)
NAME: activate_extensions
IF: defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
}
set name {}
set type {}
set if {}
set arg 0
proc record_one {} {
global name type if arg allbyname typebyif
if {$name==""} return
set allbyname($name) [list $type $arg $if]
set name {}
set type {}
set if {}
set arg 0
}
foreach line [split $pragma_def \n] {
set line [string trim $line]
if {$line==""} continue
foreach {id val} [split $line :] break
set val [string trim $val]
if {$id=="NAME"} {
record_one
set name $val
set type [string toupper $val]
} elseif {$id=="TYPE"} {
set type $val
} elseif {$id=="ARG"} {
set arg $val
} elseif {$id=="IF"} {
set if $val
} else {
error "bad pragma_def line: $line"
}
}
record_one
set allnames [lsort [array names allbyname]]
# Generate #defines for all pragma type names. Group the pragmas that are
# omit in default builds (defined(SQLITE_DEBUG) and defined(SQLITE_HAS_CODEC))
# at the end.
#
set pnum 0
foreach name $allnames {
set type [lindex $allbyname($name) 0]
if {[info exists seentype($type)]} continue
set if [lindex $allbyname($name) 2]
if {[regexp SQLITE_DEBUG $if] || [regexp SQLITE_HAS_CODEC $if]} continue
set seentype($type) 1
puts [format {#define %-35s %4d} PragTyp_$type $pnum]
incr pnum
}
foreach name $allnames {
set type [lindex $allbyname($name) 0]
if {[info exists seentype($type)]} continue
set if [lindex $allbyname($name) 2]
if {[regexp SQLITE_DEBUG $if]} continue
set seentype($type) 1
puts [format {#define %-35s %4d} PragTyp_$type $pnum]
incr pnum
}
foreach name $allnames {
set type [lindex $allbyname($name) 0]
if {[info exists seentype($type)]} continue
set seentype($type) 1
puts [format {#define %-35s %4d} PragTyp_$type $pnum]
incr pnum
}
# Generate the lookup table
#
puts "static const struct sPragmaNames \173"
puts " const char const *zName; /* Name of pragma */"
puts " int ePragTyp; /* PragTyp_XXX value */"
puts " u32 iArg; /* Extra argument */"
puts "\175 aPragmaNames\[\] = \173"
set current_if {}
set spacer [format { %26s } {}]
foreach name $allnames {
foreach {type arg if} $allbyname($name) break
if {$if!=$current_if} {
if {$current_if!=""} {puts "#endif"}
set current_if $if
if {$current_if!=""} {puts "#if $current_if"}
}
set namex [format %-26s \"$name\",]
set typex [format PragTyp_%-23s $type,]
if {[string length $arg]>10} {
puts " \173 $namex $typex\n$spacer$arg \175,"
} else {
puts " \173 $namex $typex $arg \175,"
}
}
if {$current_if!=""} {puts "#endif"}
puts "\175;"