]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Remove the OP_HexBlob instruction and code OP_Blob directly. Reduce
authordrh <drh@noemail.net>
Fri, 18 Jan 2008 14:08:24 +0000 (14:08 +0000)
committerdrh <drh@noemail.net>
Fri, 18 Jan 2008 14:08:24 +0000 (14:08 +0000)
the amount of memory allocation required to encode blob literals.
Remove the "out2" instruction type.  Other minor optimizations. (CVS 4726)

FossilOrigin-Name: 0e50c0200a3c1c04e63cbb55a7255cdbbd225347

manifest
manifest.uuid
mkopcodeh.awk
src/expr.c
src/sqliteInt.h
src/util.c
src/vdbe.c
src/vdbemem.c

index 796a47072168752c010e576d48cb00770e7e187f..9d1d6142b2ba726e0354c2c5d2e6ed9066efd8ee 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sa\stest\s(and\sfix)\sfor\spossible\scorruption\sif\smalloc()\sfails\sduring\sa\sCREATE\sINDEX\sstatement,\sthe\sapplication\scontinues\swith\sthe\stransaction,\sthen\scrashes.\s(CVS\s4725)
-D 2008-01-18T13:42:55
+C Remove\sthe\sOP_HexBlob\sinstruction\sand\scode\sOP_Blob\sdirectly.\s\sReduce\nthe\samount\sof\smemory\sallocation\srequired\sto\sencode\sblob\sliterals.\nRemove\sthe\s"out2"\sinstruction\stype.\s\sOther\sminor\soptimizations.\s(CVS\s4726)
+D 2008-01-18T14:08:24
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -69,7 +69,7 @@ F mkdll.sh 5f8438dcac98e795d7df6529159a1ec566de0183
 F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
 F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb
 F mkopcodec.awk 3fb9bf077053c968451f4dd03d11661ac373f9d1
-F mkopcodeh.awk 926deb36f57c3b573cfa79db675fdcff2ea6c5db
+F mkopcodeh.awk 89fab7d28a5ec5313f6ca985d87a31a97ef14bcb
 F mkso.sh 24bde4c09e6fe80f718db3c31c068f45e13a2f2c
 F publish.sh 1c0658c63d70f182a8f5e17cc28422f1b237f51d
 F publish_osx.sh eca87df1e3d43d128d97d3261fd48b3d6877996e
@@ -92,7 +92,7 @@ F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131
 F src/date.c 8ce763c68143b1e8fb6f79dcfc8b801853c97017
 F src/delete.c 739ccbab8fa7478762bded5c9cc67f16a4d09dbe
 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
-F src/expr.c 3162c112a327bb81aa5c38d6416b31af3569e7cd
+F src/expr.c 9ac9177466b17b57e814f0beabc9e7bba88f8e38
 F src/func.c 996071cf0af9d967e58b69fce1909555059ebc7d
 F src/hash.c 45a7005aac044b6c86bd7e49c44bc15d30006d6c
 F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
@@ -136,7 +136,7 @@ F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
 F src/shell.c 0691a3d52dc37cf6ac2f74838e5ff8ae1055ac9b
 F src/sqlite.h.in 2a7e3776534bbe6ff2cdc058f3abebe91e7e429f
 F src/sqlite3ext.h a93f59cdee3638dc0c9c086f80df743a4e68c3cb
-F src/sqliteInt.h 8389662011bc23851199750ea1e6dc1a72d26109
+F src/sqliteInt.h 9c3384439e402016037115ad143ed0c3adbd1c93
 F src/sqliteLimit.h ee4430f88f69bf63527967bb35ca52af7b0ccb1e
 F src/table.c 1aeb9eab57b4235db86fe15a35dec76fb445a9c4
 F src/tclsqlite.c 9923abeffc9b3d7dad58e92b319661521f60debf
@@ -166,16 +166,16 @@ F src/tokenize.c a4e04438c11fed2c67ec47fe3edbef9cca2d1b48
 F src/trigger.c 9bd3b6fa0beff4a02d262c96466f752ec15a7fc3
 F src/update.c 2513c6120f9510ae782446a2b839931e994b75dd
 F src/utf.c ef4b7d83bae533b76c3e1bf635b113fdad86a736
-F src/util.c 05f31144bbd3f1a24f4139ae029c42545cb72624
+F src/util.c deda8c5a400530e1c27c03619cc4cd1a06fc5281
 F src/vacuum.c 3f34f278809bf3eb0b62ec46ff779e9c385b28f0
-F src/vdbe.c 94d3da762729118e8062abf7866b22b6e41e7a3b
+F src/vdbe.c 3734b4b4fc34e46be4542593f9907a8a4d31c3d4
 F src/vdbe.h 58a7d931ffb704e034b2a725981cfa5bd406fad9
 F src/vdbeInt.h 835e6f0337ce89d705ef9a162338788808adc4b7
 F src/vdbeapi.c cb8c427a3ab646490c83204a98e94eff03ee2e89
 F src/vdbeaux.c 0d2a9730195d40f7d1156731bc69f240927255c5
 F src/vdbeblob.c e386d49d8354aa5a58f0a7f2794303442c149120
 F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6
-F src/vdbemem.c a86119b5ccc41ab8653e4746f83d591ff0ae892e
+F src/vdbemem.c 666a1d7b9d48ce6b1f6eb5e454693e0da08f6187
 F src/vtab.c 9924e37cf7f5c527aeabb5da025874af505fb91d
 F src/where.c 0cc6052f73aef0d2ce59505d7ae06d6fbf696025
 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
@@ -607,7 +607,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 87534dfff9e7a37c624a83c79f4074f29ff16c9e
-R cbf1e7869193895b2025968111b8f3b5
-U danielk1977
-Z 9aca5a3c5a8b6ed139614576f4b62520
+P 65245d9904db19568d5092926b27f0c193c9ef0b
+R c6c3d74ac2d09449d8755683e74bd3ff
+U drh
+Z c2b446e375b2c9192c3331b9823798c0
index b69cb1fabe5898a883a511af79f74a129b6773f4..76714d7cff3d0574c5f1da5966d6dd9fcd86c3de 100644 (file)
@@ -1 +1 @@
-65245d9904db19568d5092926b27f0c193c9ef0b
\ No newline at end of file
+0e50c0200a3c1c04e63cbb55a7255cdbbd225347
\ No newline at end of file
index 538bccc0cc2d4f5b6f8a99ec74fba548f3c8f361..2f92d2ef28f28e35eec9872dfa82d340d3196149 100644 (file)
@@ -55,7 +55,6 @@
   in1[name] = 0
   in2[name] = 0
   in3[name] = 0
-  out2[name] = 0
   out3[name] = 0
   for(i=3; i<NF; i++){
     if($i=="same" && $(i+1)=="as"){
@@ -77,8 +76,6 @@
       in2[name] = 1
     }else if(x=="in3"){
       in3[name] = 1
-    }else if(x=="out2"){
-      out2[name] = 1
     }else if(x=="out3"){
       out3[name] = 1
     }
@@ -133,10 +130,9 @@ END {
     if( in1[name] ) a2 = 4;
     if( in2[name] ) a3 = 8;
     if( in3[name] ) a4 = 16;
-    if( out2[name] ) a5 = 32;
-    if( out3[name] ) a6 = 64;
+    if( out3[name] ) a5 = 32;
     # bv[x] = a0+a1+a2+a3+a4+a5+a6+a7+a8+a9+a10+a11+a12+a13+a14+a15;
-    bv[x] = a0+a1+a2+a3+a4+a5+a6;
+    bv[x] = a0+a1+a2+a3+a4+a5+a6+a7;
   }
   print "\n"
   print "/* Properties such as \"out2\" or \"jump\" that are specified in"
@@ -148,8 +144,7 @@ END {
   print "#define OPFLG_IN1             0x0004  /* in1:   P1 is an input */"
   print "#define OPFLG_IN2             0x0008  /* in2:   P2 is an input */"
   print "#define OPFLG_IN3             0x0010  /* in3:   P3 is an input */"
-  print "#define OPFLG_OUT2            0x0020  /* out2:  P2 is an output */"
-  print "#define OPFLG_OUT3            0x0040  /* out3:  P3 is an output */"
+  print "#define OPFLG_OUT3            0x0020  /* out3:  P3 is an output */"
   print "#define OPFLG_INITIALIZER {\\"
   for(i=0; i<=max; i++){
     if( i%8==0 ) printf("/* %3d */",i)
index ec850ea176f709d7190c0f9d4742f397039656f7..01574f2c9903c0c30e69fba8f7f5438181c67b8e 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains routines used for analyzing expressions and
 ** for generating VDBE code that evaluates expressions in SQLite.
 **
-** $Id: expr.c,v 1.349 2008/01/18 02:31:56 drh Exp $
+** $Id: expr.c,v 1.350 2008/01/18 14:08:24 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -2004,14 +2004,15 @@ static int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
     case TK_BLOB: {
       int n;
       const char *z;
-      assert( TK_BLOB==OP_HexBlob );
+      char *zBlob;
+      assert( pExpr->token.n>=3 );
+      assert( pExpr->token.z[0]=='x' || pExpr->token.z[0]=='X' );
+      assert( pExpr->token.z[1]=='\'' );
+      assert( pExpr->token.z[pExpr->token.n-1]=='\'' );
       n = pExpr->token.n - 3;
       z = (char*)pExpr->token.z + 2;
-      assert( n>=0 );
-      if( n==0 ){
-        z = "";
-      }
-      sqlite3VdbeAddOp4(v, op, 0, target, 0, z, n);
+      zBlob = sqlite3HexToBlob(sqlite3VdbeDb(v), z, n);
+      sqlite3VdbeAddOp4(v, OP_Blob, n/2, target, 0, zBlob, P4_DYNAMIC);
       break;
     }
 #endif
index 7529318cf62454620c93d37ea18aa05a82915d1f..943e396318aa687471b19441af8aa5abee6cc884 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.651 2008/01/17 16:22:15 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.652 2008/01/18 14:08:24 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -1889,7 +1889,7 @@ int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
 char sqlite3ExprAffinity(Expr *pExpr);
 int sqlite3Atoi64(const char*, i64*);
 void sqlite3Error(sqlite3*, int, const char*,...);
-void *sqlite3HexToBlob(sqlite3*, const char *z);
+void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
 int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
 const char *sqlite3ErrStr(int);
 int sqlite3ReadSchema(Parse *pParse);
index 318bd25ade4413274507051000c643acd1dd723d..846029e9e4f8d70cc9a453038496b23ef9eb302e 100644 (file)
@@ -14,7 +14,7 @@
 ** This file contains functions for allocating memory, comparing
 ** strings, and stuff like that.
 **
-** $Id: util.c,v 1.213 2007/10/23 15:39:45 drh Exp $
+** $Id: util.c,v 1.214 2008/01/18 14:08:25 drh Exp $
 */
 #include "sqliteInt.h"
 #include <stdarg.h>
@@ -637,17 +637,17 @@ static int hexToInt(int h){
 ** binary value has been obtained from malloc and must be freed by
 ** the calling routine.
 */
-void *sqlite3HexToBlob(sqlite3 *db, const char *z){
+void *sqlite3HexToBlob(sqlite3 *db, const char *z, int n){
   char *zBlob;
   int i;
-  int n = strlen(z);
-  if( n%2 ) return 0;
 
-  zBlob = (char *)sqlite3DbMallocRaw(db, n/2);
+  zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
+  n--;
   if( zBlob ){
     for(i=0; i<n; i+=2){
       zBlob[i/2] = (hexToInt(z[i])<<4) | hexToInt(z[i+1]);
     }
+    zBlob[i/2] = 0;
   }
   return zBlob;
 }
index 50394d6cb50097862088a1d8c876dd723cdf0e9e..f7293e1b2accc9a4add729268b25cfa976f2c407 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.698 2008/01/17 16:22:15 drh Exp $
+** $Id: vdbe.c,v 1.699 2008/01/18 14:08:25 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -92,6 +92,11 @@ int sqlite3_sort_count = 0;
 */
 #ifdef SQLITE_TEST
 int sqlite3_max_blobsize = 0;
+static void updateMaxBlobsize(Mem *p){
+  if( (p->flags & (MEM_Str|MEM_Blob))!=0 && p->n>sqlite3_max_blobsize ){
+    sqlite3_max_blobsize = p->n;
+  }
+}
 #endif
 
 /*
@@ -99,9 +104,7 @@ int sqlite3_max_blobsize = 0;
 ** If it does, record the new maximum blob size.
 */
 #ifdef SQLITE_TEST
-# define UPDATE_MAX_BLOBSIZE(P)  if( ((P)->flags&(MEM_Str|MEM_Blob))!=0 \
-                                      && (P)->n>sqlite3_max_blobsize ) \
-                                          {sqlite3_max_blobsize = (P)->n;}
+# define UPDATE_MAX_BLOBSIZE(P)  updateMaxBlobsize(P)
 #else
 # define UPDATE_MAX_BLOBSIZE(P)
 #endif
@@ -509,7 +512,7 @@ int sqlite3VdbeExec(
   int nProgressOps = 0;      /* Opcodes executed since progress callback. */
 #endif
 
-  if( p->magic!=VDBE_MAGIC_RUN ) return SQLITE_MISUSE;
+  assert( p->magic==VDBE_MAGIC_RUN );  /* sqlite3_step() verifies this */
   assert( db->magic==SQLITE_MAGIC_BUSY );
   sqlite3BtreeMutexArrayEnter(&p->aMutex);
   if( p->rc==SQLITE_NOMEM ){
@@ -621,7 +624,6 @@ int sqlite3VdbeExec(
     **           in1 in2
     **           in1 in2 out3
     **           in1 in3
-    **           in1 out2
     **
     ** Variables pIn1, pIn2, and pIn3 are made to point to appropriate
     ** registers for inputs.  Variable pOut points to the output register.
@@ -646,10 +648,6 @@ int sqlite3VdbeExec(
         assert( pOp->p3<=p->nMem );
         pIn3 = &p->aMem[pOp->p3];
         REGISTER_TRACE(pOp->p3, pIn3);
-      }else if( (opProperty & OPFLG_OUT2)!=0 ){
-        assert( pOp->p2>0 );
-        assert( pOp->p2<=p->nMem );
-        pOut = &p->aMem[pOp->p2];
       }
     }else if( (opProperty & OPFLG_IN2)!=0 ){
       assert( pOp->p2>0 );
@@ -872,39 +870,6 @@ case OP_Null: {           /* out2-prerelease */
 
 
 #ifndef SQLITE_OMIT_BLOB_LITERAL
-/* Opcode: HexBlob * P2 * P4 *
-**
-** P4 is an UTF-8 SQL hex encoding of a blob. The blob is stored in
-** register P2.
-**
-** The first time this instruction executes, in transforms itself into a
-** 'Blob' opcode with a binary blob as P4.
-*/
-case OP_HexBlob: {            /* same as TK_BLOB, out2-prerelease */
-  pOp->opcode = OP_Blob;
-  pOp->p1 = strlen(pOp->p4.z)/2;
-  if( pOp->p1>SQLITE_MAX_LENGTH ){
-    goto too_big;
-  }
-  if( pOp->p1 ){
-    char *zBlob = sqlite3HexToBlob(db, pOp->p4.z);
-    if( !zBlob ) goto no_mem;
-    if( pOp->p4type==P4_DYNAMIC ){
-      sqlite3_free(pOp->p4.z);
-    }
-    pOp->p4.z = zBlob;
-    pOp->p4type = P4_DYNAMIC;
-  }else{
-    if( pOp->p4type==P4_DYNAMIC ){
-      sqlite3_free(pOp->p4.z);
-    }
-    pOp->p4type = P4_STATIC;
-    pOp->p4.z = "";
-  }
-
-  /* Fall through to the next case, OP_Blob. */
-}
-
 /* Opcode: Blob P1 P2 * P4
 **
 ** P4 points to a blob of data P1 bytes long.  Store this
@@ -4814,10 +4779,10 @@ default: {
 #ifdef SQLITE_DEBUG
     if( p->trace ){
       if( rc!=0 ) fprintf(p->trace,"rc=%d\n",rc);
-      if( (opProperty&(OPFLG_OUT2_PRERELEASE|OPFLG_OUT2))!=0 && pOp->p2>0 ){
+      if( opProperty & OPFLG_OUT2_PRERELEASE ){
         registerTrace(p->trace, pOp->p2, pOut);
       }
-      if( (opProperty&OPFLG_OUT3)!=0 && pOp->p3>0 ){
+      if( opProperty & OPFLG_OUT3 ){
         registerTrace(p->trace, pOp->p3, pOut);
       }
     }
index 443819237a03e9df0573fc837a5a294bcdd74ea3..2d9a943a4413813b007b094e03249207e4bb6002 100644 (file)
@@ -989,13 +989,15 @@ int sqlite3ValueFromExpr(
 #ifndef SQLITE_OMIT_BLOB_LITERAL
   else if( op==TK_BLOB ){
     int nVal;
+    assert( pExpr->token.n>=3 );
+    assert( pExpr->token.z[0]=='x' || pExpr->token.z[0]=='X' );
+    assert( pExpr->token.z[1]=='\'' );
+    assert( pExpr->token.z[pExpr->token.n-1]=='\'' );
     pVal = sqlite3ValueNew(db);
-    zVal = sqlite3StrNDup((char*)pExpr->token.z+1, pExpr->token.n-1);
-    if( !zVal || !pVal ) goto no_mem;
-    sqlite3Dequote(zVal);
-    nVal = strlen(zVal)/2;
-    sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal), nVal,0,sqlite3_free);
-    sqlite3_free(zVal);
+    nVal = pExpr->token.n - 3;
+    zVal = (char*)pExpr->token.z + 2;
+    sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
+                         0, sqlite3_free);
   }
 #endif