/ Check-in [2ae22dc0]
Login

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

Overview
Comment:Combine adjacent single-register OP_Copy instructions into a single multi-register OP_Copy, where possible. Fix the Synopsis comment for multi-register OP_Copy instructions to show the correct register ranges.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2ae22dc0cbed2feca4baf89d02aaace0331971d6
User & Date: drh 2013-12-20 15:59:20
Context
2013-12-20
18:44
Code simplification in sqlite3GenerateIndexKey() by making use of a subroutine found over in expr.c. check-in: 0026d335 user: drh tags: trunk
15:59
Combine adjacent single-register OP_Copy instructions into a single multi-register OP_Copy, where possible. Fix the Synopsis comment for multi-register OP_Copy instructions to show the correct register ranges. check-in: 2ae22dc0 user: drh tags: trunk
14:48
Allow any arbitrary expression as the filename in an ATTACH statement, including functions and subqueries. check-in: df70a1f3 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  3424   3424     for(pItem=pList->a, i=0; i<n; i++, pItem++){
  3425   3425       Expr *pExpr = pItem->pExpr;
  3426   3426       if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
  3427   3427         sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
  3428   3428       }else{
  3429   3429         int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
  3430   3430         if( inReg!=target+i ){
  3431         -        sqlite3VdbeAddOp2(pParse->pVdbe, copyOp, inReg, target+i);
         3431  +        VdbeOp *pOp;
         3432  +        Vdbe *v = pParse->pVdbe;
         3433  +        if( copyOp==OP_Copy
         3434  +         && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
         3435  +         && pOp->p1+pOp->p3+1==inReg
         3436  +         && pOp->p2+pOp->p3+1==target+i
         3437  +        ){
         3438  +          pOp->p3++;
         3439  +        }else{
         3440  +          sqlite3VdbeAddOp2(v, copyOp, inReg, target+i);
         3441  +        }
  3432   3442         }
  3433   3443       }
  3434   3444     }
  3435   3445     return n;
  3436   3446   }
  3437   3447   
  3438   3448   /*

Changes to src/vdbe.c.

  1107   1107       pIn1++;
  1108   1108       pOut++;
  1109   1109     }while( n-- );
  1110   1110     break;
  1111   1111   }
  1112   1112   
  1113   1113   /* Opcode: Copy P1 P2 P3 * *
  1114         -** Synopsis: r[P2@P3]=r[P1@P3]
         1114  +** Synopsis: r[P2@P3+1]=r[P1@P3+1]
  1115   1115   **
  1116   1116   ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
  1117   1117   **
  1118   1118   ** This instruction makes a deep copy of the value.  A duplicate
  1119   1119   ** is made of any string or blob constant.  See also OP_SCopy.
  1120   1120   */
  1121   1121   case OP_Copy: {

Changes to src/vdbeaux.c.

   881    881     if( c=='2' ) return pOp->p2;
   882    882     if( c=='3' ) return pOp->p3;
   883    883     if( c=='4' ) return pOp->p4.i;
   884    884     return pOp->p5;
   885    885   }
   886    886   
   887    887   /*
   888         -** Compute a string for the "comment" field of a VDBE opcode listing
          888  +** Compute a string for the "comment" field of a VDBE opcode listing.
          889  +**
          890  +** The Synopsis: field in comments in the vdbe.c source file gets converted
          891  +** to an extra string that is appended to the sqlite3OpcodeName().  In the
          892  +** absence of other comments, this synopsis becomes the comment on the opcode.
          893  +** Some translation occurs:
          894  +**
          895  +**       "PX"      ->  "r[X]"
          896  +**       "PX@PY"   ->  "r[X..X+Y-1]"  or "r[x]" if y is 0 or 1
          897  +**       "PX@PY+1" ->  "r[X..X+Y]"    or "r[x]" if y is 0
          898  +**       "PY..PY"  ->  "r[X..Y]"      or "r[x]" if y<=x
   889    899   */
   890    900   static int displayComment(
   891    901     const Op *pOp,     /* The opcode to be commented */
   892    902     const char *zP4,   /* Previously obtained value for P4 */
   893    903     char *zTemp,       /* Write result here */
   894    904     int nTemp          /* Space available in zTemp[] */
   895    905   ){
................................................................................
   915    925             int v1 = translateP(c, pOp);
   916    926             int v2;
   917    927             sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1);
   918    928             if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
   919    929               ii += 3;
   920    930               jj += sqlite3Strlen30(zTemp+jj);
   921    931               v2 = translateP(zSynopsis[ii], pOp);
   922         -            if( v2>1 ) sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
          932  +            if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){
          933  +              ii += 2;
          934  +              v2++;
          935  +            }
          936  +            if( v2>1 ){
          937  +              sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
          938  +            }
   923    939             }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
   924    940               ii += 4;
   925    941             }
   926    942           }
   927    943           jj += sqlite3Strlen30(zTemp+jj);
   928    944         }else{
   929    945           zTemp[jj++] = c;
................................................................................
  1147   1163     if( pOut==0 ) pOut = stdout;
  1148   1164     zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
  1149   1165   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
  1150   1166     displayComment(pOp, zP4, zCom, sizeof(zCom));
  1151   1167   #else
  1152   1168     zCom[0] = 0
  1153   1169   #endif
         1170  +  /* NB:  The sqlite3OpcodeName() function is implemented by code created
         1171  +  ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
         1172  +  ** information from the vdbe.c source text */
  1154   1173     fprintf(pOut, zFormat1, pc, 
  1155   1174         sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5,
  1156   1175         zCom
  1157   1176     );
  1158   1177     fflush(pOut);
  1159   1178   }
  1160   1179   #endif