Index: third_party/sqlite/src/src/recover_varint.c |
diff --git a/third_party/sqlite/sqlite-src-3100200/ext/fts5/fts5_varint.c b/third_party/sqlite/src/src/recover_varint.c |
similarity index 51% |
copy from third_party/sqlite/sqlite-src-3100200/ext/fts5/fts5_varint.c |
copy to third_party/sqlite/src/src/recover_varint.c |
index 21858506acd7dac5ac2bb36eecdac3c00e32bf74..d407738b199710118d9dfc0d3b8fb8d175c3a52b 100644 |
--- a/third_party/sqlite/sqlite-src-3100200/ext/fts5/fts5_varint.c |
+++ b/third_party/sqlite/src/src/recover_varint.c |
@@ -1,5 +1,5 @@ |
/* |
-** 2015 May 30 |
+** 2016 Feb 29 |
** |
** The author disclaims copyright to this source code. In place of |
** a legal notice, here is a blessing: |
@@ -10,78 +10,19 @@ |
** |
****************************************************************************** |
** |
-** Routines for varint serialization and deserialization. |
+** Copy of sqlite3Fts5GetVarint() from fts3_varint.c, which in turn is copied |
Scott Hess - ex-Googler
2016/03/02 01:12:08
fts5_varint.c, rather.
fts5_varint.c is the file
|
+** from SQLite core. |
*/ |
+#include <assert.h> |
+#include "sqlite3.h" |
-#include "fts5Int.h" |
- |
-/* |
-** This is a copy of the sqlite3GetVarint32() routine from the SQLite core. |
-** Except, this version does handle the single byte case that the core |
-** version depends on being handled before its function is called. |
-*/ |
-int sqlite3Fts5GetVarint32(const unsigned char *p, u32 *v){ |
- u32 a,b; |
- |
- /* The 1-byte case. Overwhelmingly the most common. */ |
- a = *p; |
- /* a: p0 (unmasked) */ |
- if (!(a&0x80)) |
- { |
- /* Values between 0 and 127 */ |
- *v = a; |
- return 1; |
- } |
- |
- /* The 2-byte case */ |
- p++; |
- b = *p; |
- /* b: p1 (unmasked) */ |
- if (!(b&0x80)) |
- { |
- /* Values between 128 and 16383 */ |
- a &= 0x7f; |
- a = a<<7; |
- *v = a | b; |
- return 2; |
- } |
- |
- /* The 3-byte case */ |
- p++; |
- a = a<<14; |
- a |= *p; |
- /* a: p0<<14 | p2 (unmasked) */ |
- if (!(a&0x80)) |
- { |
- /* Values between 16384 and 2097151 */ |
- a &= (0x7f<<14)|(0x7f); |
- b &= 0x7f; |
- b = b<<7; |
- *v = a | b; |
- return 3; |
- } |
- |
- /* A 32-bit varint is used to store size information in btrees. |
- ** Objects are rarely larger than 2MiB limit of a 3-byte varint. |
- ** A 3-byte varint is sufficient, for example, to record the size |
- ** of a 1048569-byte BLOB or string. |
- ** |
- ** We only unroll the first 1-, 2-, and 3- byte cases. The very |
- ** rare larger cases can be handled by the slower 64-bit varint |
- ** routine. |
- */ |
- { |
- u64 v64; |
- u8 n; |
- p -= 2; |
- n = sqlite3Fts5GetVarint(p, &v64); |
- *v = (u32)v64; |
- assert( n>3 && n<=9 ); |
- return n; |
- } |
-} |
- |
+/* Copied from fts3int.h. */ |
+#ifndef SQLITE_AMALGAMATION |
+typedef unsigned char u8; |
+typedef unsigned int u32; |
Scott Hess - ex-Googler
2016/03/02 01:12:08
fts5Int.h, rather. Didn't mess with these, becaus
|
+typedef sqlite3_uint64 u64; |
+#endif |
/* |
** Bitmasks used by sqlite3GetVarint(). These precomputed constants |
sdefresne
2016/03/08 15:42:36
nit: should this "sqlite3GetVarint()" be changed t
Scott Hess - ex-Googler
2016/03/08 18:37:36
Maybe? The SQLite people didn't adapt it for fts5
|
@@ -99,7 +40,7 @@ int sqlite3Fts5GetVarint32(const unsigned char *p, u32 *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. |
*/ |
-u8 sqlite3Fts5GetVarint(const unsigned char *p, u64 *v){ |
+u8 recoverGetVarint(const unsigned char *p, u64 *v){ |
u32 a,b,s; |
a = *p; |
@@ -258,85 +199,3 @@ u8 sqlite3Fts5GetVarint(const unsigned char *p, u64 *v){ |
return 9; |
} |
-/* |
-** The variable-length integer encoding is as follows: |
-** |
-** KEY: |
-** A = 0xxxxxxx 7 bits of data and one flag bit |
-** B = 1xxxxxxx 7 bits of data and one flag bit |
-** C = xxxxxxxx 8 bits of data |
-** |
-** 7 bits - A |
-** 14 bits - BA |
-** 21 bits - BBA |
-** 28 bits - BBBA |
-** 35 bits - BBBBA |
-** 42 bits - BBBBBA |
-** 49 bits - BBBBBBA |
-** 56 bits - BBBBBBBA |
-** 64 bits - BBBBBBBBC |
-*/ |
- |
-#ifdef SQLITE_NOINLINE |
-# define FTS5_NOINLINE SQLITE_NOINLINE |
-#else |
-# define FTS5_NOINLINE |
-#endif |
- |
-/* |
-** Write a 64-bit variable-length integer to memory starting at p[0]. |
-** The length of data write will be between 1 and 9 bytes. The number |
-** of bytes written is returned. |
-** |
-** A variable-length integer consists of the lower 7 bits of each byte |
-** for all bytes that have the 8th bit set and one byte with the 8th |
-** bit clear. Except, if we get to the 9th byte, it stores the full |
-** 8 bits and is the last byte. |
-*/ |
-static int FTS5_NOINLINE fts5PutVarint64(unsigned char *p, u64 v){ |
- int i, j, n; |
- u8 buf[10]; |
- if( v & (((u64)0xff000000)<<32) ){ |
- p[8] = (u8)v; |
- v >>= 8; |
- for(i=7; i>=0; i--){ |
- p[i] = (u8)((v & 0x7f) | 0x80); |
- v >>= 7; |
- } |
- return 9; |
- } |
- n = 0; |
- do{ |
- buf[n++] = (u8)((v & 0x7f) | 0x80); |
- v >>= 7; |
- }while( v!=0 ); |
- buf[0] &= 0x7f; |
- assert( n<=9 ); |
- for(i=0, j=n-1; j>=0; j--, i++){ |
- p[i] = buf[j]; |
- } |
- return n; |
-} |
- |
-int sqlite3Fts5PutVarint(unsigned char *p, u64 v){ |
- if( v<=0x7f ){ |
- p[0] = v&0x7f; |
- return 1; |
- } |
- if( v<=0x3fff ){ |
- p[0] = ((v>>7)&0x7f)|0x80; |
- p[1] = v&0x7f; |
- return 2; |
- } |
- return fts5PutVarint64(p,v); |
-} |
- |
- |
-int sqlite3Fts5GetVarintLen(u32 iVal){ |
- if( iVal<(1 << 7 ) ) return 1; |
- if( iVal<(1 << 14) ) return 2; |
- if( iVal<(1 << 21) ) return 3; |
- if( iVal<(1 << 28) ) return 4; |
- return 5; |
-} |
- |