/ Check-in [c54bd9c8]
Login

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

Overview
Comment:Remove an unnecessary stack variable from sqlite3VdbeExec().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | vector-compare
Files: files | file ages | folders
SHA1: c54bd9c82dd34951dc87848c0b19fcccaef928db
User & Date: drh 2016-08-13 14:17:02
Context
2016-08-18
15:15
Simplify the vector comparison code generator logic, and the resulting VDBE code. check-in: e2ad0b5d user: drh tags: rowvalue
2016-08-13
14:17
Remove an unnecessary stack variable from sqlite3VdbeExec(). Closed-Leaf check-in: c54bd9c8 user: drh tags: vector-compare
13:03
Improvements to commits. No code changes. check-in: 18f5a3be user: drh tags: vector-compare
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

   569    569   #ifdef SQLITE_DEBUG
   570    570     int nExtraDelete = 0;      /* Verifies FORDELETE and AUXDELETE flags */
   571    571   #endif
   572    572     int rc = SQLITE_OK;        /* Value to return */
   573    573     sqlite3 *db = p->db;       /* The database */
   574    574     u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
   575    575     u8 encoding = ENC(db);     /* The database encoding */
   576         -  int iCompare = 0;          /* Result of last OP_Compare operation */
          576  +  int iCompare = 0;          /* Result of last comparison */
   577    577     unsigned nVmStep = 0;      /* Number of virtual machine steps */
   578    578   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   579    579     unsigned nProgressLimit = 0;/* Invoke xProgress() when nVmStep reaches this */
   580    580   #endif
   581    581     Mem *aMem = p->aMem;       /* Copy of p->aMem */
   582    582     Mem *pIn1 = 0;             /* 1st input operand */
   583    583     Mem *pIn2 = 0;             /* 2nd input operand */
   584    584     Mem *pIn3 = 0;             /* 3rd input operand */
   585    585     Mem *pOut = 0;             /* Output operand */
   586    586     int *aPermute = 0;         /* Permutation of columns for OP_Compare */
   587    587     i64 lastRowid = db->lastRowid;  /* Saved value of the last insert ROWID */
   588         -  int cmpRes;                /* Result of last comparison operation */
   589    588   #ifdef VDBE_PROFILE
   590    589     u64 start;                 /* CPU clock count at start of opcode */
   591    590   #endif
   592    591     /*** INSERT STACK UNION HERE ***/
   593    592   
   594    593     assert( p->magic==VDBE_MAGIC_RUN );  /* sqlite3_step() verifies this */
   595    594     sqlite3VdbeEnter(p);
................................................................................
  2000   1999         assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
  2001   2000         assert( (flags1 & MEM_Cleared)==0 );
  2002   2001         assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 );
  2003   2002         if( (flags1&MEM_Null)!=0
  2004   2003          && (flags3&MEM_Null)!=0
  2005   2004          && (flags3&MEM_Cleared)==0
  2006   2005         ){
  2007         -        cmpRes = 0;  /* Operands are equal */
         2006  +        iCompare = 0;  /* Operands are equal */
  2008   2007         }else{
  2009         -        cmpRes = 1;  /* Operands are not equal */
         2008  +        iCompare = 1;  /* Operands are not equal */
  2010   2009         }
  2011   2010       }else{
  2012   2011         /* SQLITE_NULLEQ is clear and at least one operand is NULL,
  2013   2012         ** then the result is always NULL.
  2014   2013         ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
  2015   2014         */
  2016         -      cmpRes = 1;    /* Operands are not equal */
         2015  +      iCompare = 1;    /* Operands are not equal */
  2017   2016         if( pOp->p5 & SQLITE_STOREP2 ){
  2018   2017           pOut = &aMem[pOp->p2];
  2019   2018           memAboutToChange(p, pOut);
  2020   2019           MemSetTypeFlag(pOut, MEM_Null);
  2021   2020           REGISTER_TRACE(pOp->p2, pOut);
  2022   2021         }else{
  2023   2022           VdbeBranchTaken(2,3);
................................................................................
  2062   2061         sqlite3VdbeMemExpandBlob(pIn1);
  2063   2062         flags1 &= ~MEM_Zero;
  2064   2063       }
  2065   2064       if( flags3 & MEM_Zero ){
  2066   2065         sqlite3VdbeMemExpandBlob(pIn3);
  2067   2066         flags3 &= ~MEM_Zero;
  2068   2067       }
  2069         -    cmpRes = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
         2068  +    iCompare = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
  2070   2069     }
  2071   2070     switch( pOp->opcode ){
  2072         -    case OP_Eq:    res = cmpRes==0;     break;
  2073         -    case OP_Ne:    res = cmpRes!=0;     break;
  2074         -    case OP_Lt:    res = cmpRes<0;      break;
  2075         -    case OP_Le:    res = cmpRes<=0;     break;
  2076         -    case OP_Gt:    res = cmpRes>0;      break;
  2077         -    case OP_Ge:    res = cmpRes>=0;     break;
         2071  +    case OP_Eq:    res = iCompare==0;     break;
         2072  +    case OP_Ne:    res = iCompare!=0;     break;
         2073  +    case OP_Lt:    res = iCompare<0;      break;
         2074  +    case OP_Le:    res = iCompare<=0;     break;
         2075  +    case OP_Gt:    res = iCompare>0;      break;
         2076  +    default:       res = iCompare>=0;     break;
  2078   2077     }
  2079   2078   
  2080   2079     /* Undo any changes made by applyAffinity() to the input registers. */
  2081   2080     assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
  2082   2081     pIn1->flags = flags1;
  2083   2082     assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
  2084   2083     pIn3->flags = flags3;
................................................................................
  2112   2111   ** operator and if the result of that Eq would be NULL or false (0), then
  2113   2112   ** then jump to P2.  If the result of comparing the two previous operands
  2114   2113   ** using Eq would have been true (1), then fall through.
  2115   2114   */
  2116   2115   case OP_ElseNotEq: {       /* same as TK_ESCAPE, jump */
  2117   2116     assert( pOp>aOp );
  2118   2117     assert( pOp[-1].opcode==OP_Lt || pOp[-1].opcode==OP_Gt );
  2119         -  VdbeBranchTaken(cmpRes!=0, 2);
  2120         -  if( cmpRes!=0 ) goto jump_to_p2;
         2118  +  VdbeBranchTaken(iCompare!=0, 2);
         2119  +  if( iCompare!=0 ) goto jump_to_p2;
  2121   2120     break;
  2122   2121   }
  2123   2122   
  2124   2123   
  2125   2124   /* Opcode: Permutation * * * P4 *
  2126   2125   **
  2127   2126   ** Set the permutation used by the OP_Compare operator to be the array