/ Check-in [9a4199ae]
Login

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

Overview
Comment:Slightly faster implementation of the length() SQL function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9a4199aedb039141a50a68943ef863d7df9637ada318793cce6c12b9d39bcdc5
User & Date: drh 2018-01-23 04:22:33
Context
2018-01-23
07:11
Skip defining WIN32_LEAN_AND_MEAN when it is already defined. check-in: 195f5323 user: mistachkin tags: trunk
04:22
Slightly faster implementation of the length() SQL function. check-in: 9a4199ae user: drh tags: trunk
03:44
Slightly faster function dispatch in the virtual machine by avoiding unnecessary reinitialization of variables that are already correctly initialized. check-in: edd4e687 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/func.c.

    98     98   ** Implementation of the length() function
    99     99   */
   100    100   static void lengthFunc(
   101    101     sqlite3_context *context,
   102    102     int argc,
   103    103     sqlite3_value **argv
   104    104   ){
   105         -  int len;
   106         -
   107    105     assert( argc==1 );
   108    106     UNUSED_PARAMETER(argc);
   109    107     switch( sqlite3_value_type(argv[0]) ){
   110    108       case SQLITE_BLOB:
   111    109       case SQLITE_INTEGER:
   112    110       case SQLITE_FLOAT: {
   113    111         sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
   114    112         break;
   115    113       }
   116    114       case SQLITE_TEXT: {
   117    115         const unsigned char *z = sqlite3_value_text(argv[0]);
          116  +      const unsigned char *z0;
          117  +      unsigned char c;
   118    118         if( z==0 ) return;
   119         -      len = 0;
   120         -      while( *z ){
   121         -        len++;
   122         -        SQLITE_SKIP_UTF8(z);
          119  +      z0 = z;
          120  +      while( (c = *z)!=0 ){
          121  +        z++;
          122  +        if( c>=0xc0 ){
          123  +          while( (*z & 0xc0)==0x80 ){ z++; z0++; }
          124  +        }
   123    125         }
   124         -      sqlite3_result_int(context, len);
          126  +      sqlite3_result_int(context, (int)(z-z0));
   125    127         break;
   126    128       }
   127    129       default: {
   128    130         sqlite3_result_null(context);
   129    131         break;
   130    132       }
   131    133     }