/ Check-in [163bfae8]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Fix compiler warnings and change the nullMem structure initializer into a format that MSVC can understand.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | micro-optimizations
Files: files | file ages | folders
SHA1: 163bfae8583b2d3002a3a43d6bf8a66fefd73acb
User & Date: drh 2014-09-18 01:21:43
Context
2014-09-18
01:29
Merge micro-optimizations into trunk after fixing the build on MSVC. Performance now shows 7.58% faster than the 3.8.6 release on x64 with gcc 4.8.1 and -Os. check-in: 1de558bc user: drh tags: trunk
01:21
Fix compiler warnings and change the nullMem structure initializer into a format that MSVC can understand. Closed-Leaf check-in: 163bfae8 user: drh tags: micro-optimizations
2014-09-17
23:37
Performance improvement and slight size reduction to the comparison operators in the VDBE. check-in: 14052a7d user: drh tags: micro-optimizations
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

   301    301       ** signed integer value might cause an integer overflow inside of the
   302    302       ** xMalloc().  Hence we limit the maximum size to 0x7fffff00, giving
   303    303       ** 255 bytes of overhead.  SQLite itself will never use anything near
   304    304       ** this amount.  The only way to reach the limit is with sqlite3_malloc() */
   305    305       p = 0;
   306    306     }else if( sqlite3GlobalConfig.bMemstat ){
   307    307       sqlite3_mutex_enter(mem0.mutex);
   308         -    mallocWithAlarm(n, &p);
          308  +    mallocWithAlarm((int)n, &p);
   309    309       sqlite3_mutex_leave(mem0.mutex);
   310    310     }else{
   311    311       p = sqlite3GlobalConfig.m.xMalloc((int)n);
   312    312     }
   313    313     assert( EIGHT_BYTE_ALIGNMENT(p) );  /* IMP: R-04675-44850 */
   314    314     return p;
   315    315   }
................................................................................
   545    545     ** argument to xRealloc is always a value returned by a prior call to
   546    546     ** xRoundup. */
   547    547     nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes);
   548    548     if( nOld==nNew ){
   549    549       pNew = pOld;
   550    550     }else if( sqlite3GlobalConfig.bMemstat ){
   551    551       sqlite3_mutex_enter(mem0.mutex);
   552         -    sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
          552  +    sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
   553    553       nDiff = nNew - nOld;
   554    554       if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
   555    555             mem0.alarmThreshold-nDiff ){
   556    556         sqlite3MallocAlarm(nDiff);
   557    557       }
   558    558       assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
   559    559       assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
   560    560       pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
   561    561       if( pNew==0 && mem0.alarmCallback ){
   562         -      sqlite3MallocAlarm(nBytes);
          562  +      sqlite3MallocAlarm((int)nBytes);
   563    563         pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
   564    564       }
   565    565       if( pNew ){
   566    566         nNew = sqlite3MallocSize(pNew);
   567    567         sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
   568    568       }
   569    569       sqlite3_mutex_leave(mem0.mutex);
................................................................................
   695    695           memcpy(pNew, p, db->lookaside.sz);
   696    696           sqlite3DbFree(db, p);
   697    697         }
   698    698       }else{
   699    699         assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
   700    700         assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
   701    701         sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
   702         -      pNew = sqlite3_realloc(p, n);
          702  +      pNew = sqlite3_realloc64(p, n);
   703    703         if( !pNew ){
   704    704           sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
   705    705           db->mallocFailed = 1;
   706    706         }
   707    707         sqlite3MemdebugSetType(pNew, MEMTYPE_DB | 
   708    708               (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
   709    709       }

Changes to src/table.c.

    69     69     if( p->nRow==0 ){
    70     70       p->nColumn = nCol;
    71     71       for(i=0; i<nCol; i++){
    72     72         z = sqlite3_mprintf("%s", colv[i]);
    73     73         if( z==0 ) goto malloc_failed;
    74     74         p->azResult[p->nData++] = z;
    75     75       }
    76         -  }else if( p->nColumn!=nCol ){
           76  +  }else if( (int)p->nColumn!=nCol ){
    77     77       sqlite3_free(p->zErrMsg);
    78     78       p->zErrMsg = sqlite3_mprintf(
    79     79          "sqlite3_get_table() called with two or more incompatible queries"
    80     80       );
    81     81       p->rc = SQLITE_ERROR;
    82     82       return 1;
    83     83     }

Changes to src/vdbeapi.c.

   799    799     ** using gcc, we force nullMem to be 8-byte aligned using the magical
   800    800     ** __attribute__((aligned(8))) macro.  */
   801    801     static const Mem nullMem 
   802    802   #if defined(SQLITE_DEBUG) && defined(__GNUC__)
   803    803       __attribute__((aligned(8))) 
   804    804   #endif
   805    805       = {
   806         -         .flags      = MEM_Null,
   807         -         .enc        = 0,
   808         -         .n          = 0,
   809         -         .r          = (double)0,
   810         -         .u          = {0},
   811         -         .z          = 0,
   812         -         .zMalloc    = 0,
   813         -         .db         = 0,
   814         -         .xDel       = 0,
          806  +        /* .u          = */ {0},
          807  +        /* .flags      = */ MEM_Null,
          808  +        /* .enc        = */ 0,
          809  +        /* .n          = */ 0,
          810  +        /* .r          = */ (double)0,
          811  +        /* .z          = */ 0,
          812  +        /* .zMalloc    = */ 0,
          813  +        /* .db         = */ 0,
          814  +        /* .xDel       = */ 0,
   815    815   #ifdef SQLITE_DEBUG
   816         -         .pScopyFrom = 0,
   817         -         .pFiller    = 0,
          816  +        /* .pScopyFrom = */ 0,
          817  +        /* .pFiller    = */ 0,
   818    818   #endif
   819    819         };
   820    820     return &nullMem;
   821    821   }
   822    822   
   823    823   /*
   824    824   ** Check to see if column iCol of the given statement is valid.  If
................................................................................
  1189   1189     sqlite3_uint64 nData, 
  1190   1190     void (*xDel)(void*)
  1191   1191   ){
  1192   1192     assert( xDel!=SQLITE_DYNAMIC );
  1193   1193     if( nData>0x7fffffff ){
  1194   1194       return invokeValueDestructor(zData, xDel, 0);
  1195   1195     }else{
  1196         -    return bindText(pStmt, i, zData, nData, xDel, 0);
         1196  +    return bindText(pStmt, i, zData, (int)nData, xDel, 0);
  1197   1197     }
  1198   1198   }
  1199   1199   int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
  1200   1200     int rc;
  1201   1201     Vdbe *p = (Vdbe *)pStmt;
  1202   1202     rc = vdbeUnbind(p, i);
  1203   1203     if( rc==SQLITE_OK ){
................................................................................
  1246   1246     unsigned char enc
  1247   1247   ){
  1248   1248     assert( xDel!=SQLITE_DYNAMIC );
  1249   1249     if( nData>0x7fffffff ){
  1250   1250       return invokeValueDestructor(zData, xDel, 0);
  1251   1251     }else{
  1252   1252       if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
  1253         -    return bindText(pStmt, i, zData, nData, xDel, enc);
         1253  +    return bindText(pStmt, i, zData, (int)nData, xDel, enc);
  1254   1254     }
  1255   1255   }
  1256   1256   #ifndef SQLITE_OMIT_UTF16
  1257   1257   int sqlite3_bind_text16(
  1258   1258     sqlite3_stmt *pStmt, 
  1259   1259     int i, 
  1260   1260     const void *zData,