mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-16 23:02:26 +03:00
Performance enhancement in sqlite3PutVarint().
FossilOrigin-Name: a929be551924144c9bc7aab608404d59e479abb5
This commit is contained in:
@@ -3307,38 +3307,23 @@ u64 sqlite3LogEstToInt(LogEst);
|
||||
/*
|
||||
** Routines to read and write variable-length integers. These used to
|
||||
** be defined locally, but now we use the varint routines in the util.c
|
||||
** file. Code should use the MACRO forms below, as the Varint32 versions
|
||||
** are coded to assume the single byte case is already handled (which
|
||||
** the MACRO form does).
|
||||
** file.
|
||||
*/
|
||||
int sqlite3PutVarint(unsigned char*, u64);
|
||||
int sqlite3PutVarint32(unsigned char*, u32);
|
||||
u8 sqlite3GetVarint(const unsigned char *, u64 *);
|
||||
u8 sqlite3GetVarint32(const unsigned char *, u32 *);
|
||||
int sqlite3VarintLen(u64 v);
|
||||
|
||||
/*
|
||||
** The header of a record consists of a sequence variable-length integers.
|
||||
** These integers are almost always small and are encoded as a single byte.
|
||||
** The following macros take advantage this fact to provide a fast encode
|
||||
** and decode of the integers in a record header. It is faster for the common
|
||||
** case where the integer is a single byte. It is a little slower when the
|
||||
** integer is two or more bytes. But overall it is faster.
|
||||
**
|
||||
** The following expressions are equivalent:
|
||||
**
|
||||
** x = sqlite3GetVarint32( A, &B );
|
||||
** x = sqlite3PutVarint32( A, B );
|
||||
**
|
||||
** x = getVarint32( A, B );
|
||||
** x = putVarint32( A, B );
|
||||
**
|
||||
** The common case is for a varint to be a single byte. They following
|
||||
** macros handle the common case without a procedure call, but then call
|
||||
** the procedure for larger varints.
|
||||
*/
|
||||
#define getVarint32(A,B) \
|
||||
(u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B)))
|
||||
#define putVarint32(A,B) \
|
||||
(u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
|
||||
sqlite3PutVarint32((A),(B)))
|
||||
sqlite3PutVarint((A),(B)))
|
||||
#define getVarint sqlite3GetVarint
|
||||
#define putVarint sqlite3PutVarint
|
||||
|
||||
|
||||
Reference in New Issue
Block a user