/ Check-in [f83daa16]
Login

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

Overview
Comment:Changes to sqlite3ScratchMalloc() that make the entire memory allocation interface a little faster and about 100 bytes smaller.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f83daa16f65ef35062412e88c214852a4aeb3da2
User & Date: drh 2014-08-23 19:04:55
Context
2014-08-23
19:08
Fix a variable-declaration after code problem in btree.c. Harmless in GCC and CLANG but unacceptable for MSVC. check-in: 45abd5c0 user: drh tags: trunk
19:04
Changes to sqlite3ScratchMalloc() that make the entire memory allocation interface a little faster and about 100 bytes smaller. check-in: f83daa16 user: drh tags: trunk
18:17
Make the implementation of the sqlite3_aggregate_context() interface faster for second an subsequent invocations. This helps all aggregate functions to perform better. check-in: 802148f3 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

   348    348   ** embedded processor.
   349    349   */
   350    350   void *sqlite3ScratchMalloc(int n){
   351    351     void *p;
   352    352     assert( n>0 );
   353    353   
   354    354     sqlite3_mutex_enter(mem0.mutex);
          355  +  sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
   355    356     if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){
   356    357       p = mem0.pScratchFree;
   357    358       mem0.pScratchFree = mem0.pScratchFree->pNext;
   358    359       mem0.nScratchFree--;
   359    360       sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1);
   360         -    sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
   361    361       sqlite3_mutex_leave(mem0.mutex);
   362    362     }else{
   363         -    if( sqlite3GlobalConfig.bMemstat ){
   364         -      sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
   365         -      n = mallocWithAlarm(n, &p);
   366         -      if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
          363  +    sqlite3_mutex_leave(mem0.mutex);
          364  +    p = sqlite3Malloc(n);
          365  +    if( sqlite3GlobalConfig.bMemstat && p ){
          366  +      sqlite3_mutex_enter(mem0.mutex);
          367  +      sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p));
   367    368         sqlite3_mutex_leave(mem0.mutex);
   368         -    }else{
   369         -      sqlite3_mutex_leave(mem0.mutex);
   370         -      p = sqlite3GlobalConfig.m.xMalloc(n);
   371    369       }
   372    370       sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
   373    371     }
   374    372     assert( sqlite3_mutex_notheld(mem0.mutex) );
   375    373   
   376    374   
   377    375   #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)