Simplifications to the OP_MakeRecord opcode and the sqlite3VdbeSerialPut()

helper function.

FossilOrigin-Name: 7277a769694787e0332d1a4efc02041834661e2a
This commit is contained in:
drh 2013-12-09 23:17:22 +00:00
parent 401387553d
commit 038b7bc4ef
6 changed files with 30 additions and 47 deletions

View File

@ -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

View File

@ -1 +1 @@
c43b59dac1fbb67ec3a9d921005543046ad416ce
7277a769694787e0332d1a4efc02041834661e2a

View 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 );

View 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);

View 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;
}

View 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);
}