/ Check-in [4bc8a48e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Optimize calls to sqlite3_mprintf("%z...") so that they attempt to append text onto the end of the existing memory allocation rather than reallocating and copying.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4bc8a48e644562f6e6192f4c6fc4a70f6bb59f8126ed6c6dc876bedf65d74cda
User & Date: drh 2018-02-20 15:23:37
Context
2018-02-20
16:39
Remove a superfluous "#if 1". No logic changes. check-in: caaffd32 user: drh tags: trunk
15:23
Optimize calls to sqlite3_mprintf("%z...") so that they attempt to append text onto the end of the existing memory allocation rather than reallocating and copying. check-in: 4bc8a48e user: drh tags: trunk
13:46
Remove a lot of the text describing extended format options from the documentation on sqlite3_mprintf() and friends, since that information is now covered by the separate printf.html document. Provide links to that other document. No changes to code. check-in: 99eec556 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   587    587   SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB
   588    588   SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
   589    589   SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
   590    590   SHELL_OPT += -DSQLITE_INTROSPECTION_PRAGMAS
   591    591   FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
   592    592   FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
   593    593   FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
          594  +FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
   594    595   FUZZCHECK_SRC = $(TOP)/test/fuzzcheck.c $(TOP)/test/ossfuzz.c
   595    596   DBFUZZ_OPT = 
   596    597   
   597    598   # This is the default Makefile target.  The objects listed here
   598    599   # are what get build when you type just "make" with no arguments.
   599    600   #
   600    601   all:	sqlite3.h libsqlite3.la sqlite3$(TEXE) $(HAVE_TCL:1=libtclsqlite3.la)

Changes to Makefile.msc.

  1611   1611   !ENDIF
  1612   1612   
  1613   1613   # <<mark>>
  1614   1614   # Extra compiler options for various test tools.
  1615   1615   #
  1616   1616   MPTESTER_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5
  1617   1617   FUZZERSHELL_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1
  1618         -FUZZCHECK_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ -DSQLITE_MAX_MEMORY=50000000
         1618  +FUZZCHECK_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ -DSQLITE_MAX_MEMORY=50000000 -DSQLITE_PRINTF_PRECISION_LIMIT=1000
  1619   1619   FUZZCHECK_SRC = $(TOP)\test\fuzzcheck.c $(TOP)\test\ossfuzz.c
  1620   1620   OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c
  1621   1621   DBFUZZ_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION
  1622   1622   KV_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ
  1623   1623   DBSELFTEST_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5
  1624   1624   ST_COMPILE_OPTS = -DSQLITE_THREADSAFE=0
  1625   1625   

Changes to main.mk.

   515    515   SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB
   516    516   SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
   517    517   SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
   518    518   SHELL_OPT += -DSQLITE_INTROSPECTION_PRAGMAS
   519    519   FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
   520    520   FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5
   521    521   FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
          522  +FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
   522    523   DBFUZZ_OPT =
   523    524   KV_OPT = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ
   524    525   ST_OPT = -DSQLITE_THREADSAFE=0
   525    526   
   526    527   # This is the default Makefile target.  The objects listed here
   527    528   # are what get build when you type just "make" with no arguments.
   528    529   #

Changes to src/printf.c.

   202    202     double rounder;            /* Used for rounding floating point values */
   203    203     etByte flag_dp;            /* True if decimal point should be shown */
   204    204     etByte flag_rtz;           /* True if trailing zeros should be removed */
   205    205   #endif
   206    206     PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
   207    207     char buf[etBUFSIZE];       /* Conversion buffer */
   208    208   
          209  +  /* pAccum never starts out with an empty buffer that was obtained from 
          210  +  ** malloc().  This precondition is required by the mprintf("%z...")
          211  +  ** optimization. */
          212  +  assert( pAccum->nChar>0 || (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 );
          213  +
   209    214     bufpt = 0;
   210    215     if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){
   211    216       pArgList = va_arg(ap, PrintfArguments*);
   212    217       bArgList = 1;
   213    218     }else{
   214    219       bArgList = 0;
   215    220     }
................................................................................
   677    682             xtype = etSTRING;
   678    683           }else{
   679    684             bufpt = va_arg(ap,char*);
   680    685           }
   681    686           if( bufpt==0 ){
   682    687             bufpt = "";
   683    688           }else if( xtype==etDYNSTRING ){
          689  +          if( pAccum->nChar==0 && pAccum->mxAlloc && width==0 && precision<0 ){
          690  +            /* Special optimization for sqlite3_mprintf("%z..."):
          691  +            ** Extend an existing memory allocation rather than creating
          692  +            ** a new one. */
          693  +            assert( (pAccum->printfFlags&SQLITE_PRINTF_MALLOCED)==0 );
          694  +            pAccum->zText = bufpt;
          695  +            pAccum->nAlloc = sqlite3DbMallocSize(pAccum->db, bufpt);
          696  +            pAccum->nChar = 0x7fffffff & (int)strlen(bufpt);
          697  +            pAccum->printfFlags |= SQLITE_PRINTF_MALLOCED;
          698  +            length = 0;
          699  +            break;
          700  +          }
   684    701             zExtra = bufpt;
   685    702           }
   686    703           if( precision>=0 ){
   687    704             if( flag_altform2 ){
   688    705               /* Set length to the number of bytes needed in order to display
   689    706               ** precision characters */
   690    707               unsigned char *z = (unsigned char*)bufpt;