]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Simplifications to the OP_MakeRecord opcode and the sqlite3VdbeSerialPut()
authordrh <drh@noemail.net>
Mon, 9 Dec 2013 23:17:22 +0000 (23:17 +0000)
committerdrh <drh@noemail.net>
Mon, 9 Dec 2013 23:17:22 +0000 (23:17 +0000)
helper function.

FossilOrigin-Name: 7277a769694787e0332d1a4efc02041834661e2a

manifest
manifest.uuid
src/vdbe.c
src/vdbeInt.h
src/vdbeaux.c
src/vdbemem.c

index c03216855d52f111d917ccf2eba99d2083957367..6901566020cd7f54c10c72ea2ea086017d980165 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Correct\sthe\sVFS\sname\sas\sreported\sby\sthe\sfile\scontrol\swhen\sexplicitly\susing\sthe\s'win32-longpath'\sVFS.
-D 2013-12-09T21:48:49.439
+C Simplifications\sto\sthe\sOP_MakeRecord\sopcode\sand\sthe\ssqlite3VdbeSerialPut()\nhelper\sfunction.
+D 2013-12-09T23:17:22.886
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -280,13 +280,13 @@ F src/update.c d1c2477dcf14d90999d1935af4efb4806553250b
 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
 F src/util.c 76ed0519296e3f62e97e57dab1999e34184c8e49
 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
-F src/vdbe.c 5338567d17c055b26b9b3d280bdd8aa4e8e13d3f
+F src/vdbe.c 4bfb1fe75a0ad08646e9b82670691c62699bc5ee
 F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644
-F src/vdbeInt.h 05fbda0e061dbc4aaa2709a8cccf3515c245b263
+F src/vdbeInt.h 7e38eef8f4bd7141e1638b0eacaebf9bc41b26bc
 F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed
-F src/vdbeaux.c 09b79d475f5af2b3b5068f639609d88e0ced9d95
+F src/vdbeaux.c d64bc2a057e77aef3e2a4bc6670b80f516a36d55
 F src/vdbeblob.c 8cd05a5630e6d5563ad017bf82edaf812b28acde
-F src/vdbemem.c f12d087d92f57fc302028ac1b45374bf8a454d7e
+F src/vdbemem.c 2293b66374f4adf54bbdcd662c05a003318600e1
 F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147
 F src/vdbetrace.c e7ec40e1999ff3c6414424365d5941178966dcbc
 F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
@@ -1146,7 +1146,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P 6b51863553e51334880fb322bdf74e51e35d0e61
-R 02366bc03c0aa38f7c8d01b5c92fd1d6
-U mistachkin
-Z d9c38f842954179c02eb8030f4c6e2c4
+P c43b59dac1fbb67ec3a9d921005543046ad416ce
+R c11616a6774c1e84bdec6602d7be1c45
+U drh
+Z 4d30567758bc854237be3d93d5ebeaed
index de251e1a194da9759814e99f58db00bba2e353a1..fae0da29de04a7afc5abc83176cf461c7b75daaa 100644 (file)
@@ -1 +1 @@
-c43b59dac1fbb67ec3a9d921005543046ad416ce
\ No newline at end of file
+7277a769694787e0332d1a4efc02041834661e2a
\ No newline at end of file
index 1108a85341f55e1321f72ae2014ef55dafe99545..a0a69e8a5caabd46b51b9108302acd71c521065f 100644 (file)
@@ -2599,29 +2599,27 @@ case OP_MakeRecord: {
   ** out how much space is required for the new record.
   */
   assert( pData0<=pLast );
-  pRec = pData0;
+  pRec = pLast;
   do{
     assert( memIsValid(pRec) );
     if( zAffinity ){
       applyAffinity(pRec, zAffinity[pRec-pData0], encoding);
     }
-    if( (pRec->flags&MEM_Zero)!=0 && pRec->n>0 ){
-      sqlite3VdbeMemExpandBlob(pRec);
-    }
     serial_type = sqlite3VdbeSerialType(pRec, file_format);
     len = sqlite3VdbeSerialTypeLen(serial_type);
+    if( pRec->flags & MEM_Zero ){
+      if( nData ){
+        sqlite3VdbeMemExpandBlob(pRec);
+      }else{
+        nZero += pRec->u.nZero;
+        len -= pRec->u.nZero;
+      }
+    }
     nData += len;
     testcase( serial_type==127 );
     testcase( serial_type==128 );
     nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
-    if( pRec->flags & MEM_Zero ){
-      /* Only pure zero-filled BLOBs can be input to this Opcode.
-      ** We do not allow blobs with a prefix and a zero-filled tail. */
-      nZero += pRec->u.nZero;
-    }else if( len ){
-      nZero = 0;
-    }
-  }while( (++pRec)<=pLast );
+  }while( (--pRec)>=pData0 );
 
   /* Add the initial header varint and total the size */
   testcase( nHdr==126 );
@@ -2635,7 +2633,7 @@ case OP_MakeRecord: {
     nHdr += nVarint;
     if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
   }
-  nByte = nHdr+nData-nZero;
+  nByte = nHdr+nData;
   if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
     goto too_big;
   }
@@ -2657,8 +2655,8 @@ case OP_MakeRecord: {
   pRec = pData0;
   do{
     serial_type = sqlite3VdbeSerialType(pRec, file_format);
-    i += putVarint32(&zNewRecord[i], serial_type);      /* serial type */
-    j += sqlite3VdbeSerialPut(&zNewRecord[j], (int)(nByte-j), pRec,file_format);
+    i += putVarint32(&zNewRecord[i], serial_type);            /* serial type */
+    j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, file_format); /* content */
   }while( (++pRec)<=pLast );
   assert( i==nHdr );
   assert( j==nByte );
index 371c4d6dc18e725ecae5ec1f6c2b1ffd941f2b11..b01af201880295c9829f2a3e64b626af8bed022c 100644 (file)
@@ -389,7 +389,7 @@ void sqlite3VdbePrintOp(FILE*, int, Op*);
 #endif
 u32 sqlite3VdbeSerialTypeLen(u32);
 u32 sqlite3VdbeSerialType(Mem*, int);
-u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
+u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, int);
 u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
 void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
 
index 5b5d82aed862dda633eb1763053d719a00fc5998..c610de456298ba99e0ca80b38ddfc6754ec4c272 100644 (file)
@@ -2827,20 +2827,15 @@ static u64 floatSwap(u64 in){
 ** buf. It is assumed that the caller has allocated sufficient space.
 ** Return the number of bytes written.
 **
-** nBuf is the amount of space left in buf[].  nBuf must always be
-** large enough to hold the entire field.  Except, if the field is
-** a blob with a zero-filled tail, then buf[] might be just the right
-** size to hold everything except for the zero-filled tail.  If buf[]
-** is only big enough to hold the non-zero prefix, then only write that
-** prefix into buf[].  But if buf[] is large enough to hold both the
-** prefix and the tail then write the prefix and set the tail to all
-** zeros.
+** nBuf is the amount of space left in buf[].  The caller is responsible
+** for allocating enough space to buf[] to hold the entire field, exclusive
+** of the pMem->u.nZero bytes for a MEM_Zero value.
 **
 ** Return the number of bytes actually written into buf[].  The number
 ** of bytes in the zero-filled tail is included in the return value only
 ** if those bytes were zeroed in buf[].
 */ 
-u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){
+u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, int file_format){
   u32 serial_type = sqlite3VdbeSerialType(pMem, file_format);
   u32 len;
 
@@ -2856,7 +2851,6 @@ u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){
       v = pMem->u.i;
     }
     len = i = sqlite3VdbeSerialTypeLen(serial_type);
-    assert( len<=(u32)nBuf );
     while( i-- ){
       buf[i] = (u8)(v&0xFF);
       v >>= 8;
@@ -2868,17 +2862,8 @@ u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){
   if( serial_type>=12 ){
     assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
              == (int)sqlite3VdbeSerialTypeLen(serial_type) );
-    assert( pMem->n<=nBuf );
     len = pMem->n;
     memcpy(buf, pMem->z, len);
-    if( pMem->flags & MEM_Zero ){
-      len += pMem->u.nZero;
-      assert( nBuf>=0 );
-      if( len > (u32)nBuf ){
-        len = (u32)nBuf;
-      }
-      memset(&buf[pMem->n], 0, len-pMem->n);
-    }
     return len;
   }
 
index 8a3acd5308e2268af08b2feb5cb223343f7c6cc8..451744291f9f5b92d0769006e8040bd374d2b003 100644 (file)
@@ -1221,7 +1221,7 @@ static void recordFunc(
   }else{
     aRet[0] = nSerial+1;
     sqlite3PutVarint(&aRet[1], iSerial);
-    sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format);
+    sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], file_format);
     sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
     sqlite3DbFree(db, aRet);
   }