/ Check-in [3b3e32d4]
Login

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

Overview
Comment:Small size and performance optimization in the bytecode engine.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3b3e32d4cd07a1d2d1708fffa47819345ae6b39205a9f548280d499c8f481d64
User & Date: drh 2017-09-20 17:49:12
References
2017-09-21
01:04
Revert one performance improvement changes from check-in [3b3e32d4cd07] as it was causing a reference to an uninitialized value. check-in: f8b1c64d user: drh tags: trunk
Context
2017-09-20
18:07
The BLOB returned by sqlite3VdbeMemFromBtree() does not need to be zero-terminated. check-in: e0af9a90 user: drh tags: trunk
17:49
Small size and performance optimization in the bytecode engine. check-in: 3b3e32d4 user: drh tags: trunk
10:47
Improved resolution of large integer values in "CAST(x AS NUMERIC)". check-in: 7f2bd4ff user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbemem.c.

   110    110   int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
   111    111   #ifndef SQLITE_OMIT_UTF16
   112    112     int rc;
   113    113   #endif
   114    114     assert( (pMem->flags&MEM_RowSet)==0 );
   115    115     assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE
   116    116              || desiredEnc==SQLITE_UTF16BE );
   117         -  if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
          117  +  if( pMem->enc==desiredEnc || !(pMem->flags&MEM_Str) ){
   118    118       return SQLITE_OK;
   119    119     }
   120    120     assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
   121    121   #ifdef SQLITE_OMIT_UTF16
   122    122     return SQLITE_ERROR;
   123    123   #else
   124    124   
................................................................................
   204    204       return sqlite3VdbeMemGrow(pMem, szNew, 0);
   205    205     }
   206    206     assert( (pMem->flags & MEM_Dyn)==0 );
   207    207     pMem->z = pMem->zMalloc;
   208    208     pMem->flags &= (MEM_Null|MEM_Int|MEM_Real);
   209    209     return SQLITE_OK;
   210    210   }
          211  +
          212  +/*
          213  +** It is already known that pMem contains an unterminated string.
          214  +** Add the zero terminator.
          215  +*/
          216  +static SQLITE_NOINLINE int vdbeMemAddTerminator(Mem *pMem){
          217  +  if( sqlite3VdbeMemGrow(pMem, pMem->n+2, 1) ){
          218  +    return SQLITE_NOMEM_BKPT;
          219  +  }
          220  +  pMem->z[pMem->n] = 0;
          221  +  pMem->z[pMem->n+1] = 0;
          222  +  pMem->flags |= MEM_Term;
          223  +  return SQLITE_OK;
          224  +}
   211    225   
   212    226   /*
   213    227   ** Change pMem so that its MEM_Str or MEM_Blob value is stored in
   214    228   ** MEM.zMalloc, where it can be safely written.
   215    229   **
   216    230   ** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
   217    231   */
   218    232   int sqlite3VdbeMemMakeWriteable(Mem *pMem){
   219    233     assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
   220    234     assert( (pMem->flags&MEM_RowSet)==0 );
   221    235     if( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ){
   222    236       if( ExpandBlob(pMem) ) return SQLITE_NOMEM;
   223    237       if( pMem->szMalloc==0 || pMem->z!=pMem->zMalloc ){
   224         -      if( sqlite3VdbeMemGrow(pMem, pMem->n + 2, 1) ){
   225         -        return SQLITE_NOMEM_BKPT;
   226         -      }
   227         -      pMem->z[pMem->n] = 0;
   228         -      pMem->z[pMem->n+1] = 0;
   229         -      pMem->flags |= MEM_Term;
          238  +      int rc = vdbeMemAddTerminator(pMem);
          239  +      if( rc ) return rc;
   230    240       }
   231    241     }
   232    242     pMem->flags &= ~MEM_Ephem;
   233    243   #ifdef SQLITE_DEBUG
   234    244     pMem->pScopyFrom = 0;
   235    245   #endif
   236    246   
................................................................................
   261    271     memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
   262    272     pMem->n += pMem->u.nZero;
   263    273     pMem->flags &= ~(MEM_Zero|MEM_Term);
   264    274     return SQLITE_OK;
   265    275   }
   266    276   #endif
   267    277   
   268         -/*
   269         -** It is already known that pMem contains an unterminated string.
   270         -** Add the zero terminator.
   271         -*/
   272         -static SQLITE_NOINLINE int vdbeMemAddTerminator(Mem *pMem){
   273         -  if( sqlite3VdbeMemGrow(pMem, pMem->n+2, 1) ){
   274         -    return SQLITE_NOMEM_BKPT;
   275         -  }
   276         -  pMem->z[pMem->n] = 0;
   277         -  pMem->z[pMem->n+1] = 0;
   278         -  pMem->flags |= MEM_Term;
   279         -  return SQLITE_OK;
   280         -}
   281         -
   282    278   /*
   283    279   ** Make sure the given Mem is \u0000 terminated.
   284    280   */
   285    281   int sqlite3VdbeMemNulTerminate(Mem *pMem){
   286    282     assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
   287    283     testcase( (pMem->flags & (MEM_Term|MEM_Str))==(MEM_Term|MEM_Str) );
   288    284     testcase( (pMem->flags & (MEM_Term|MEM_Str))==0 );