mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-09 14:21:03 +03:00
Add the sqlite3PutVarint32 routine as an alternative to sqlite3PutVarint.
Gives 0.5% speed increase. (CVS 4968) FossilOrigin-Name: b2517a7d8f7275943d44cc301f9d54fc8a4653e7
This commit is contained in:
20
src/util.c
20
src/util.c
@@ -14,7 +14,7 @@
|
||||
** This file contains functions for allocating memory, comparing
|
||||
** strings, and stuff like that.
|
||||
**
|
||||
** $Id: util.c,v 1.218 2008/04/04 15:12:22 drh Exp $
|
||||
** $Id: util.c,v 1.219 2008/04/05 18:41:43 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdarg.h>
|
||||
@@ -497,6 +497,24 @@ int sqlite3PutVarint(unsigned char *p, u64 v){
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is a faster version of sqlite3PutVarint() that only
|
||||
** works for 32-bit positive integers and which is optimized for
|
||||
** the common case of small integers.
|
||||
*/
|
||||
int sqlite3PutVarint32(unsigned char *p, u32 v){
|
||||
if( (v & ~0x7f)==0 ){
|
||||
p[0] = v;
|
||||
return 1;
|
||||
}else if( (v & ~0x3fff)==0 ){
|
||||
p[0] = (v>>7) | 0x80;
|
||||
p[1] = v & 0x7f;
|
||||
return 2;
|
||||
}else{
|
||||
return sqlite3PutVarint(p, v);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Read a 64-bit variable-length integer from memory starting at p[0].
|
||||
** Return the number of bytes read. The value is stored in *v.
|
||||
|
||||
Reference in New Issue
Block a user