/ Check-in [2e195e96]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Avoid unnecessary strlen() calls in the OP_String opcode. (CVS 2768)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2e195e96bcbad104da09ebe6cef617e0e9ef1884
User & Date: drh 2005-11-16 04:34:32
Context
2005-11-16
12:53
Do not allow aggregate functions in a WHERE clause. Ticket #1514. (CVS 2769) check-in: bb866ed8 user: drh tags: trunk
04:34
Avoid unnecessary strlen() calls in the OP_String opcode. (CVS 2768) check-in: 2e195e96 user: drh tags: trunk
2005-11-15
02:14
Fix a bug in UTF-16 handling introduced by the previous check-in. (CVS 2767) check-in: 25fa16a2 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.497 2005/11/15 02:14:01 drh Exp $
           46  +** $Id: vdbe.c,v 1.498 2005/11/16 04:34:32 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include "vdbeInt.h"
    52     52   
    53     53   /*
................................................................................
   634    634     pTos->flags |= MEM_Real;
   635    635     sqlite3VdbeChangeEncoding(pTos, db->enc);
   636    636     break;
   637    637   }
   638    638   
   639    639   /* Opcode: String8 * * P3
   640    640   **
   641         -** P3 points to a nul terminated UTF-8 string. This opcode is transformed
          641  +** P3 points to a nul terminated UTF-8 string that is P1 character long
          642  +** (not counting the nul terminator). This opcode is transformed
   642    643   ** into an OP_String before it is executed for the first time.
   643    644   */
   644    645   case OP_String8: {         /* same as TK_STRING */
   645         -#ifndef SQLITE_OMIT_UTF16
          646  +  assert( pOp->p3!=0 );
   646    647     pOp->opcode = OP_String;
          648  +  pOp->p1 = strlen(pOp->p3);
   647    649   
   648         -  assert( pOp->p3!=0 );
          650  +#ifndef SQLITE_OMIT_UTF16
   649    651     if( db->enc!=SQLITE_UTF8 ){
   650    652       pTos++;
   651    653       sqlite3VdbeMemSetStr(pTos, pOp->p3, -1, SQLITE_UTF8, SQLITE_STATIC);
   652    654       if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pTos, db->enc) ) goto no_mem;
   653    655       if( SQLITE_OK!=sqlite3VdbeMemDynamicify(pTos) ) goto no_mem;
   654    656       pTos->flags &= ~(MEM_Dyn);
   655    657       pTos->flags |= MEM_Static;
   656    658       if( pOp->p3type==P3_DYNAMIC ){
   657    659         sqliteFree(pOp->p3);
   658    660       }
   659    661       pOp->p3type = P3_DYNAMIC;
   660    662       pOp->p3 = pTos->z;
          663  +    pOp->p1 *= 2;
   661    664       break;
   662    665     }
   663    666   #endif
   664    667     /* Otherwise fall through to the next case, OP_String */
   665    668   }
   666    669     
   667         -/* Opcode: String * * P3
          670  +/* Opcode: String P1 * P3
   668    671   **
   669         -** The string value P3 is pushed onto the stack.  If P3==0 then a
   670         -** NULL is pushed onto the stack. P3 is assumed to be a nul terminated
   671         -** string encoded with the database native encoding.
          672  +** The string value P3 of length P1 is pushed onto the stack.
   672    673   */
   673    674   case OP_String: {
   674    675     pTos++;
   675    676     assert( pOp->p3!=0 );
   676    677     pTos->flags = MEM_Str|MEM_Static|MEM_Term;
   677    678     pTos->z = pOp->p3;
   678         -#ifndef SQLITE_OMIT_UTF16
   679         -  if( db->enc==SQLITE_UTF8 ){
   680         -    pTos->n = strlen(pTos->z);
   681         -  }else{
   682         -    pTos->n  = sqlite3utf16ByteLen(pTos->z, -1);
   683         -  }
   684         -#else
   685         -  assert( db->enc==SQLITE_UTF8 );
   686         -  pTos->n = strlen(pTos->z);
   687         -#endif
          679  +  pTos->n = pOp->p1;
   688    680     pTos->enc = db->enc;
   689    681     break;
   690    682   }
   691    683   
   692    684   /* Opcode: Null * * *
   693    685   **
   694    686   ** Push a NULL onto the stack.