/ Check-in [3f55484e]
Login

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

Overview
Comment:Handle the 4-byte integer case in the stackless routine.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1:3f55484e81000c75e231f5580632a68e782ded4f
User & Date: drh 2014-08-22 14:56:13
Context
2014-08-22
15:19
Improve the performance and reduce the size of the sqlite3VdbeSerialGet() routine by avoiding the use of stack. check-in: ebc10e46 user: drh tags: trunk
14:56
Handle the 4-byte integer case in the stackless routine. Closed-Leaf check-in: 3f55484e user: drh tags: experimental
14:34
Get the sqlite3VdbeSerialGet() routine to run faster by avoiding the use of local variables. check-in: 8267d821 user: drh tags: experimental
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

  2957   2957   /* Input "x" is a sequence of unsigned characters that represent a
  2958   2958   ** big-endian integer.  Return the equivalent native integer
  2959   2959   */
  2960   2960   #define ONE_BYTE_INT(x)    ((i8)(x)[0])
  2961   2961   #define TWO_BYTE_INT(x)    (256*(i8)((x)[0])|(x)[1])
  2962   2962   #define THREE_BYTE_INT(x)  (65536*(i8)((x)[0])|((x)[1]<<8)|(x)[2])
  2963   2963   #define FOUR_BYTE_UINT(x)  (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
         2964  +#define FOUR_BYTE_INT(x) (16777216*(i8)((x)[0])|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
  2964   2965   
  2965   2966   /*
  2966   2967   ** Deserialize the data blob pointed to by buf as serial type serial_type
  2967   2968   ** and store the result in pMem.  Return the number of bytes read.
  2968   2969   **
  2969   2970   ** This function is implemented as two separate routines for performance.
  2970   2971   ** The few cases that require local variables are broken out into a separate
................................................................................
  2972   2973   ** is avoided.
  2973   2974   */ 
  2974   2975   static u32 SQLITE_NOINLINE serialGet(
  2975   2976     const unsigned char *buf,     /* Buffer to deserialize from */
  2976   2977     u32 serial_type,              /* Serial type to deserialize */
  2977   2978     Mem *pMem                     /* Memory cell to write value into */
  2978   2979   ){
  2979         -  u64 x;
  2980         -  u32 y = FOUR_BYTE_UINT(buf);
  2981         -  if( serial_type==4 ){
  2982         -    pMem->u.i = (i64)*(int*)&y;
  2983         -    pMem->flags = MEM_Int;
  2984         -    testcase( pMem->u.i<0 );
  2985         -    return 4;
  2986         -  }
  2987         -  x = (((u64)y)<<32)|FOUR_BYTE_UINT(buf+4);
         2980  +  u64 x = FOUR_BYTE_UINT(buf);
         2981  +  u32 y = FOUR_BYTE_UINT(buf+4);
         2982  +  x = (x<<32) + y;
  2988   2983     if( serial_type==6 ){
  2989   2984       pMem->u.i = *(i64*)&x;
  2990   2985       pMem->flags = MEM_Int;
  2991   2986       testcase( pMem->u.i<0 );
  2992   2987     }else{
  2993   2988   #if !defined(NDEBUG) && !defined(SQLITE_OMIT_FLOATING_POINT)
  2994   2989       /* Verify that integers and floating point values use the same
................................................................................
  3034   3029         return 2;
  3035   3030       }
  3036   3031       case 3: { /* 3-byte signed integer */
  3037   3032         pMem->u.i = THREE_BYTE_INT(buf);
  3038   3033         pMem->flags = MEM_Int;
  3039   3034         testcase( pMem->u.i<0 );
  3040   3035         return 3;
         3036  +    }
         3037  +    case 4: { /* 4-byte signed integer */
         3038  +      pMem->u.i = FOUR_BYTE_INT(buf);
         3039  +      pMem->flags = MEM_Int;
         3040  +      testcase( pMem->u.i<0 );
         3041  +      return 4;
  3041   3042       }
  3042   3043       case 5: { /* 6-byte signed integer */
  3043   3044         pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf);
  3044   3045         pMem->flags = MEM_Int;
  3045   3046         testcase( pMem->u.i<0 );
  3046   3047         return 6;
  3047   3048       }
  3048         -    case 4:   /* 4-byte signed integer */
  3049   3049       case 6:   /* 8-byte signed integer */
  3050   3050       case 7: { /* IEEE floating point */
  3051         -      /* These three cases require local variables, so do them in a 
  3052         -      ** separate routine to avoid having to move the frame pointer in
  3053         -      ** the common case */
         3051  +      /* These use local variables, so do them in a separate routine
         3052  +      ** to avoid having to move the frame pointer in the common case */
  3054   3053         return serialGet(buf,serial_type,pMem);
  3055   3054       }
  3056   3055       case 8:    /* Integer 0 */
  3057   3056       case 9: {  /* Integer 1 */
  3058   3057         pMem->u.i = serial_type-8;
  3059   3058         pMem->flags = MEM_Int;
  3060   3059         return 0;