]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make the implementation of the sqlite3_aggregate_context() interface faster
authordrh <drh@noemail.net>
Sat, 23 Aug 2014 18:17:19 +0000 (18:17 +0000)
committerdrh <drh@noemail.net>
Sat, 23 Aug 2014 18:17:19 +0000 (18:17 +0000)
for second an subsequent invocations.  This helps all aggregate functions to
perform better.

FossilOrigin-Name: 802148f3110462eac939d53ce08eb9a2f6aac739

manifest
manifest.uuid
src/vdbeapi.c

index a5fad99ba947a7d1dfe073ea4331c3139a8985db..aa0c254b02106257202835632a2fb3c73f2ca121 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Improved\sperformance\sin\sthe\stype\shandling\sof\sarithmetic\soperators\sin\sthe\sVDBE.
-D 2014-08-23T17:41:15.456
+C Make\sthe\simplementation\sof\sthe\ssqlite3_aggregate_context()\sinterface\sfaster\nfor\ssecond\san\ssubsequent\sinvocations.\s\sThis\shelps\sall\saggregate\sfunctions\sto\nperform\sbetter.
+D 2014-08-23T18:17:19.059
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -287,7 +287,7 @@ F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
 F src/vdbe.c 52ee5d589cbb171a8b096f210b69deb4a33c4369
 F src/vdbe.h c63fad052c9e7388d551e556e119c0bcf6bebdf8
 F src/vdbeInt.h 764a055bc9a3e61a30ba37cd4c1826f62bcf8759
-F src/vdbeapi.c 49b8d2943d02d276b4efef114578251a3277f47d
+F src/vdbeapi.c cda974083d7597f807640d344ffcf76d872201ce
 F src/vdbeaux.c dba006f67c9fd1b1d07ee7fb0fb38aa1905161d1
 F src/vdbeblob.c 848238dc73e93e48432991bb5651bf87d865eca4
 F src/vdbemem.c f2e162888521a9af35d608ac4c13db4991dfb417
@@ -1188,7 +1188,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 25f2246be404f38b4f8dd70397cd1454d46358c4
-R 2a69d28bf2271ac25d420aa80c42027b
+P 0c0a603950c97837442d82886f947aab0acbd805
+R d4bdc3de1168bf2d862dde32e02d949b
 U drh
-Z c64b6b94b93d1da5e9e0a75cc412b115
+Z 5d66d6e81701eb9b183824f31680ac42
index 53a34bdd8dc8831f7a4713e21080622076f2cb9d..5b8e019c7e89e280a07952acaba13c715277fd71 100644 (file)
@@ -1 +1 @@
-0c0a603950c97837442d82886f947aab0acbd805
\ No newline at end of file
+802148f3110462eac939d53ce08eb9a2f6aac739
\ No newline at end of file
index 675361013a00c519c818bdba2aed578280d2357f..b2d805915337e40af0f7eaf1cc48059f314205a0 100644 (file)
@@ -606,32 +606,42 @@ void sqlite3InvalidFunction(
   sqlite3_free(zErr);
 }
 
+/*
+** Create a new aggregate context for p and return a pointer to
+** its pMem->z element.
+*/
+static SQLITE_NOINLINE void *createAggContext(sqlite3_context *p, int nByte){
+  Mem *pMem = p->pMem;
+  assert( (pMem->flags & MEM_Agg)==0 );
+  if( nByte<=0 ){
+    sqlite3VdbeMemReleaseExternal(pMem);
+    pMem->flags = MEM_Null;
+    pMem->z = 0;
+  }else{
+    sqlite3VdbeMemGrow(pMem, nByte, 0);
+    pMem->flags = MEM_Agg;
+    pMem->u.pDef = p->pFunc;
+    if( pMem->z ){
+      memset(pMem->z, 0, nByte);
+    }
+  }
+  return (void*)pMem->z;
+}
+
 /*
 ** Allocate or return the aggregate context for a user function.  A new
 ** context is allocated on the first call.  Subsequent calls return the
 ** same context that was returned on prior calls.
 */
 void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){
-  Mem *pMem;
   assert( p && p->pFunc && p->pFunc->xStep );
   assert( sqlite3_mutex_held(p->s.db->mutex) );
-  pMem = p->pMem;
   testcase( nByte<0 );
-  if( (pMem->flags & MEM_Agg)==0 ){
-    if( nByte<=0 ){
-      sqlite3VdbeMemReleaseExternal(pMem);
-      pMem->flags = MEM_Null;
-      pMem->z = 0;
-    }else{
-      sqlite3VdbeMemGrow(pMem, nByte, 0);
-      pMem->flags = MEM_Agg;
-      pMem->u.pDef = p->pFunc;
-      if( pMem->z ){
-        memset(pMem->z, 0, nByte);
-      }
-    }
+  if( (p->pMem->flags & MEM_Agg)==0 ){
+    return createAggContext(p, nByte);
+  }else{
+    return (void*)p->pMem->z;
   }
-  return (void*)pMem->z;
 }
 
 /*