summaryrefslogtreecommitdiffstats
path: root/programs/lz4io.c
diff options
context:
space:
mode:
authorTakayuki MATSUOKA <takayuki.matsuoka@gmail.com>2015-02-12 11:18:16 (GMT)
committerTakayuki MATSUOKA <takayuki.matsuoka@gmail.com>2015-03-02 04:38:27 (GMT)
commitb372f45093aa8d86f7a99b7dd5e2deaeffb10033 (patch)
tree4a9dac1d3aa046f560677d1ec01a35128e3caa1b /programs/lz4io.c
parent01a24afdcf867a901076eaa87434b3dcb39d526f (diff)
downloadlz4-b372f45093aa8d86f7a99b7dd5e2deaeffb10033.zip
lz4-b372f45093aa8d86f7a99b7dd5e2deaeffb10033.tar.gz
lz4-b372f45093aa8d86f7a99b7dd5e2deaeffb10033.tar.bz2
Add Neil's method to isSparse()
Diffstat (limited to 'programs/lz4io.c')
-rw-r--r--programs/lz4io.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/programs/lz4io.c b/programs/lz4io.c
index b1067ac..c69275d 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -220,6 +220,7 @@ int LZ4IO_setSparseFile(int yes)
static int isSparse(const void* p, size_t size)
{
#if 0
+ /* naive */
const char* p8 = p;
for(; size; --size)
{
@@ -230,7 +231,8 @@ static int isSparse(const void* p, size_t size)
++p8;
}
return 1;
-#else
+#elif 0
+ /* xz method */
const U64* p64 = (const U64*) p;
const char* p8 = (const char*) p;
const size_t n = size / sizeof(*p64);
@@ -253,6 +255,10 @@ static int isSparse(const void* p, size_t size)
}
return 1;
+#else
+ /* Neil's */
+ const char* buf = (const char*) p;
+ return buf[0] == 0 && !memcmp(buf, buf + 1, size - 1);
#endif
}
#endif /* LZ4IO_ENABLE_SPARSE_FILE */