/ Check-in [80985505]
Login

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

Overview
Comment:Faster version of sqlite3VdbeSerialGet. (CVS 1495)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 80985505fe8ba8e505842dae95d37bf412fc586d
User & Date: drh 2004-05-30 01:51:52
Context
2004-05-30
02:14
Additional minor speed improvements. (CVS 1496) check-in: a90264c0 user: drh tags: trunk
01:51
Faster version of sqlite3VdbeSerialGet. (CVS 1495) check-in: 80985505 user: drh tags: trunk
01:38
Do not include the P3 parameter on OP_Integer opcodes if the integer will fit in 32 bits. The P3 conversion is slow. (CVS 1494) check-in: fcd84eba user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
....
1233
1234
1235
1236
1237
1238
1239

1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
....
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285







1286
1287
1288
1289
1290
1291
1292
  assert( serial_type!=0 );
  if( serial_type>6 ){
    return (serial_type-12)/2;
  }else{
    static u8 aSize[] = { 0, 1, 2, 4, 8, 8, 0, };
    return aSize[serial_type];
  }
#if 0
  switch(serial_type){
    case 6: return 0;                  /* NULL */
    case 1: return 1;                  /* 1 byte integer */
    case 2: return 2;                  /* 2 byte integer */
    case 3: return 4;                  /* 4 byte integer */
    case 4: return 8;                  /* 8 byte integer */
    case 5: return 8;                  /* 8 byte float */
  }
  assert( serial_type>=12 );
  return ((serial_type-12)>>1);        /* text or blob */
#endif
}

/*
** Write the serialized data blob for the value stored in pMem into 
** buf. It is assumed that the caller has allocated sufficient space.
** Return the number of bytes written.
*/ 
................................................................................
int sqlite3VdbeSerialGet(
  const unsigned char *buf,     /* Buffer to deserialize from */
  u32 serial_type,              /* Serial type to deserialize */
  Mem *pMem                     /* Memory cell to write value into */
){
  int len;


  assert( serial_type!=0 );

  /* memset(pMem, 0, sizeof(pMem)); */
  pMem->flags = 0;
  pMem->z = 0;

  /* NULL */
  if( serial_type==6 ){
    pMem->flags = MEM_Null;
    pMem->type = SQLITE3_NULL;
    return 0;
  }
 
  /* Integer and Real */
  if( serial_type<=5 ){
    u64 v = 0;
    int n;
    len = sqlite3VdbeSerialTypeLen(serial_type);

    if( buf[0]&0x80 ){
      v = -1;
    }
    for(n=0; n<len; n++){
      v = (v<<8) | buf[n];
    }
................................................................................
      pMem->r = *(double*)&v;
      pMem->type = SQLITE3_FLOAT;
    }else{
      pMem->flags = MEM_Int;
      pMem->i = *(i64*)&v;
      pMem->type = SQLITE3_INTEGER;
    }
    return len;
  }

  /* String or blob */
  assert( serial_type>=12 );
  len = sqlite3VdbeSerialTypeLen(serial_type);
  pMem->z = (char *)buf;
  pMem->n = len;
  if( serial_type&0x01 ){
    pMem->flags = MEM_Str | MEM_Ephem;
  }else{
    pMem->flags = MEM_Blob | MEM_Ephem;







  }
  return len;
}

/*
** The following is the comparison function for (non-integer)
** keys in the btrees.  This function returns negative, zero, or







<
<
<
<
<
<
<
<
<
<
<
<







 







>

<
<
<
<
<
<
|
<
<
<
<
<
|
<


<







 







|
<
<
|
<
<
|
|
|
|
|
|
>
>
>
>
>
>
>







1168
1169
1170
1171
1172
1173
1174












1175
1176
1177
1178
1179
1180
1181
....
1221
1222
1223
1224
1225
1226
1227
1228
1229






1230





1231

1232
1233

1234
1235
1236
1237
1238
1239
1240
....
1243
1244
1245
1246
1247
1248
1249
1250


1251


1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
  assert( serial_type!=0 );
  if( serial_type>6 ){
    return (serial_type-12)/2;
  }else{
    static u8 aSize[] = { 0, 1, 2, 4, 8, 8, 0, };
    return aSize[serial_type];
  }












}

/*
** Write the serialized data blob for the value stored in pMem into 
** buf. It is assumed that the caller has allocated sufficient space.
** Return the number of bytes written.
*/ 
................................................................................
int sqlite3VdbeSerialGet(
  const unsigned char *buf,     /* Buffer to deserialize from */
  u32 serial_type,              /* Serial type to deserialize */
  Mem *pMem                     /* Memory cell to write value into */
){
  int len;

  len = sqlite3VdbeSerialTypeLen(serial_type);
  assert( serial_type!=0 );






  if( serial_type<=5 ){





    /* Integer and Real */

    u64 v = 0;
    int n;


    if( buf[0]&0x80 ){
      v = -1;
    }
    for(n=0; n<len; n++){
      v = (v<<8) | buf[n];
    }
................................................................................
      pMem->r = *(double*)&v;
      pMem->type = SQLITE3_FLOAT;
    }else{
      pMem->flags = MEM_Int;
      pMem->i = *(i64*)&v;
      pMem->type = SQLITE3_INTEGER;
    }
  }else if( serial_type>=12 ){


    /* String or blob */


    pMem->z = (char *)buf;
    pMem->n = len;
    if( serial_type&0x01 ){
      pMem->flags = MEM_Str | MEM_Ephem;
    }else{
      pMem->flags = MEM_Blob | MEM_Ephem;
    }
  }else{
    /* NULL */
    assert( serial_type==6 );
    assert( len==0 );
    pMem->flags = MEM_Null;
    pMem->type = SQLITE3_NULL;
  }
  return len;
}

/*
** The following is the comparison function for (non-integer)
** keys in the btrees.  This function returns negative, zero, or