Fix opensource version
PiperOrigin-RevId: 343272548
This commit is contained in:
committed by
Victor Costan
parent
616b8229b6
commit
01a566f825
@@ -180,9 +180,9 @@ if(GTEST_FOUND)
|
|||||||
endif(GTEST_FOUND)
|
endif(GTEST_FOUND)
|
||||||
|
|
||||||
find_package(Gflags QUIET)
|
find_package(Gflags QUIET)
|
||||||
if(GFLAGS_FOUND)
|
if(GFLAGS_FOUND OR GFLAGS_TARGET)
|
||||||
set(HAVE_GFLAGS 1)
|
set(HAVE_GFLAGS 1)
|
||||||
endif(GFLAGS_FOUND)
|
endif(GFLAGS_FOUND OR GFLAGS_TARGET)
|
||||||
|
|
||||||
configure_file(
|
configure_file(
|
||||||
"cmake/config.h.in"
|
"cmake/config.h.in"
|
||||||
@@ -261,7 +261,7 @@ if(SNAPPY_BUILD_TESTS)
|
|||||||
"snappy-test.cc"
|
"snappy-test.cc"
|
||||||
)
|
)
|
||||||
target_compile_definitions(snappy_unittest PRIVATE -DHAVE_CONFIG_H)
|
target_compile_definitions(snappy_unittest PRIVATE -DHAVE_CONFIG_H)
|
||||||
target_link_libraries(snappy_unittest snappy ${GFLAGS_LIBRARIES})
|
target_link_libraries(snappy_unittest snappy ${GFLAGS_LIBRARIES} ${GTEST_LIBRARY})
|
||||||
|
|
||||||
if(HAVE_LIBZ)
|
if(HAVE_LIBZ)
|
||||||
target_link_libraries(snappy_unittest z)
|
target_link_libraries(snappy_unittest z)
|
||||||
|
|||||||
@@ -28,6 +28,9 @@
|
|||||||
/* Define to 1 if you have the `z' library (-lz). */
|
/* Define to 1 if you have the `z' library (-lz). */
|
||||||
#cmakedefine HAVE_LIBZ 1
|
#cmakedefine HAVE_LIBZ 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `lz4' library (-llz4). */
|
||||||
|
#cmakedefine HAVE_LIBLZ4 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/mman.h> header file. */
|
/* Define to 1 if you have the <sys/mman.h> header file. */
|
||||||
#cmakedefine HAVE_SYS_MMAN_H 1
|
#cmakedefine HAVE_SYS_MMAN_H 1
|
||||||
|
|
||||||
|
|||||||
71
snappy.cc
71
snappy.cc
@@ -69,6 +69,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -92,38 +94,38 @@ using internal::LITERAL;
|
|||||||
// in the low byte. Because length will never be 0, we use zero as an indicator
|
// in the low byte. Because length will never be 0, we use zero as an indicator
|
||||||
// for an exceptional value (copy 3 tag or a literal > 60 bytes).
|
// for an exceptional value (copy 3 tag or a literal > 60 bytes).
|
||||||
constexpr size_t kLiteralOffset = 256;
|
constexpr size_t kLiteralOffset = 256;
|
||||||
|
inline constexpr uint16_t MakeEntry(uint16_t len, uint16_t offset) {
|
||||||
|
return len | (offset << 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline constexpr uint16_t OffsetAndLength(uint8_t tag, int type) {
|
||||||
|
return type == 3 ? 0 // copy-4 (or type == 3)
|
||||||
|
: type == 2 ? MakeEntry((tag >> 2) + 1, 0) // copy-2
|
||||||
|
: type == 1 ? MakeEntry(((tag >> 2) & 7) + 4, tag >> 5) // copy-1
|
||||||
|
: tag < 60 * 4 ? MakeEntry((tag >> 2) + 1, 1)
|
||||||
|
: 0; // long literal
|
||||||
|
}
|
||||||
|
|
||||||
inline constexpr uint16_t OffsetAndLength(uint8_t tag) {
|
inline constexpr uint16_t OffsetAndLength(uint8_t tag) {
|
||||||
switch (tag & 3) {
|
return OffsetAndLength(tag, tag & 3);
|
||||||
case 0: {
|
|
||||||
if (tag >= 60 * 4) {
|
|
||||||
return 0; // literal longer then 60 bytes is done in fallback.
|
|
||||||
}
|
|
||||||
int len = (tag >> 2) + 1;
|
|
||||||
// We include a spurious offset for literals explained in the code.
|
|
||||||
return len | kLiteralOffset;
|
|
||||||
}
|
|
||||||
case 1: {
|
|
||||||
int len = ((tag >> 2) & 7) + 4;
|
|
||||||
int off = tag >> 5;
|
|
||||||
return len | (off << 8);
|
|
||||||
}
|
|
||||||
case 2: {
|
|
||||||
int len = (tag >> 2) + 1;
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return 0; // copy 3 tags are done in fallback.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constexpr std::array<uint16_t, 256> OffsetAndLengthTable() {
|
template <size_t... Ints>
|
||||||
std::array<uint16_t, 256> arr{};
|
struct index_sequence {};
|
||||||
for (int i = 0; i < 256; i++) arr[i] = OffsetAndLength(i);
|
|
||||||
return arr;
|
template <std::size_t N, size_t... Is>
|
||||||
|
struct make_index_sequence : make_index_sequence<N - 1, N - 1, Is...> {};
|
||||||
|
|
||||||
|
template <size_t... Is>
|
||||||
|
struct make_index_sequence<0, Is...> : index_sequence<Is...> {};
|
||||||
|
|
||||||
|
template <size_t... seq>
|
||||||
|
constexpr std::array<uint16_t, 256> MakeTable(index_sequence<seq...>) {
|
||||||
|
return std::array<uint16_t, 256>{OffsetAndLength(seq)...};
|
||||||
}
|
}
|
||||||
|
|
||||||
alignas(64) const std::array<uint16_t, 256> offset_and_length_table =
|
alignas(64) constexpr std::array<uint16_t, 256> offset_and_length_table =
|
||||||
OffsetAndLengthTable();
|
MakeTable(make_index_sequence<256>{});
|
||||||
|
|
||||||
// Any hash function will produce a valid compressed bitstream, but a good
|
// Any hash function will produce a valid compressed bitstream, but a good
|
||||||
// hash function reduces the number of collisions and thus yields better
|
// hash function reduces the number of collisions and thus yields better
|
||||||
@@ -812,7 +814,6 @@ static inline bool LeftShiftOverflows(uint8_t value, uint32_t shift) {
|
|||||||
std::pair<const uint8_t*, char*> DecompressBranchless(
|
std::pair<const uint8_t*, char*> DecompressBranchless(
|
||||||
const uint8_t* ip, const uint8_t* ip_limit, char* op_ptr, char* op_base,
|
const uint8_t* ip, const uint8_t* ip_limit, char* op_ptr, char* op_base,
|
||||||
char* op_limit_min_slop_ptr) {
|
char* op_limit_min_slop_ptr) {
|
||||||
constexpr size_t kSlopBytes = 64;
|
|
||||||
std::ptrdiff_t op = op_ptr - op_base;
|
std::ptrdiff_t op = op_ptr - op_base;
|
||||||
std::ptrdiff_t op_limit_min_slop = op_limit_min_slop_ptr - op_base;
|
std::ptrdiff_t op_limit_min_slop = op_limit_min_slop_ptr - op_base;
|
||||||
std::ptrdiff_t op_limit = op_limit_min_slop + kSlopBytes - 1;
|
std::ptrdiff_t op_limit = op_limit_min_slop + kSlopBytes - 1;
|
||||||
@@ -890,7 +891,7 @@ std::pair<const uint8_t*, char*> DecompressBranchless(
|
|||||||
}
|
}
|
||||||
// By choosing literals to have kLiteralOffset this test will
|
// By choosing literals to have kLiteralOffset this test will
|
||||||
// always succeed for literals.
|
// always succeed for literals.
|
||||||
if (SNAPPY_PREDICT_FALSE(offset < len)) {
|
if (SNAPPY_PREDICT_FALSE(std::size_t(offset) < len)) {
|
||||||
assert(tag_type != 0);
|
assert(tag_type != 0);
|
||||||
// offset 0 is an error.
|
// offset 0 is an error.
|
||||||
if (SNAPPY_PREDICT_FALSE(offset == 0)) break;
|
if (SNAPPY_PREDICT_FALSE(offset == 0)) break;
|
||||||
@@ -1111,11 +1112,12 @@ class SnappyDecompressor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
constexpr uint32_t CalculateNeeded(uint8_t tag) {
|
constexpr uint32_t CalculateNeeded(uint8_t tag) {
|
||||||
uint32_t needed = (0x05030201 >> ((tag * 8) & 31)) & 0xFF;
|
return ((tag & 3) == 0 && tag >= (60 * 4))
|
||||||
if ((tag & 3) == 0 && tag >= (60 * 4)) needed = (tag >> 2) - 58;
|
? (tag >> 2) - 58
|
||||||
return needed;
|
: (0x05030201 >> ((tag * 8) & 31)) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201402L
|
||||||
constexpr bool VerifyCalculateNeeded() {
|
constexpr bool VerifyCalculateNeeded() {
|
||||||
for (int i = 0; i < 1; i++) {
|
for (int i = 0; i < 1; i++) {
|
||||||
if (CalculateNeeded(i) != (char_table[i] >> 11) + 1) return false;
|
if (CalculateNeeded(i) != (char_table[i] >> 11) + 1) return false;
|
||||||
@@ -1126,6 +1128,7 @@ constexpr bool VerifyCalculateNeeded() {
|
|||||||
// Make sure CalculateNeeded is correct by verifying it against the established
|
// Make sure CalculateNeeded is correct by verifying it against the established
|
||||||
// table encoding the number of added bytes needed.
|
// table encoding the number of added bytes needed.
|
||||||
static_assert(VerifyCalculateNeeded(), "");
|
static_assert(VerifyCalculateNeeded(), "");
|
||||||
|
#endif // c++14
|
||||||
|
|
||||||
bool SnappyDecompressor::RefillTag() {
|
bool SnappyDecompressor::RefillTag() {
|
||||||
const char* ip = ip_;
|
const char* ip = ip_;
|
||||||
@@ -1354,7 +1357,7 @@ class SnappyIOVecWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char* GetOutputPtr() { return nullptr; }
|
char* GetOutputPtr() { return nullptr; }
|
||||||
char* GetBase(char** op_limit_min_slop) { return nullptr; }
|
char* GetBase(char**) { return nullptr; }
|
||||||
void SetOutputPtr(char* op) {
|
void SetOutputPtr(char* op) {
|
||||||
// TODO: Switch to [[maybe_unused]] when we can assume C++17.
|
// TODO: Switch to [[maybe_unused]] when we can assume C++17.
|
||||||
(void)op;
|
(void)op;
|
||||||
@@ -1611,7 +1614,7 @@ class SnappyDecompressionValidator {
|
|||||||
inline SnappyDecompressionValidator() : expected_(0), produced_(0) {}
|
inline SnappyDecompressionValidator() : expected_(0), produced_(0) {}
|
||||||
inline void SetExpectedLength(size_t len) { expected_ = len; }
|
inline void SetExpectedLength(size_t len) { expected_ = len; }
|
||||||
size_t GetOutputPtr() { return produced_; }
|
size_t GetOutputPtr() { return produced_; }
|
||||||
char* GetBase(char** op_limit_min_slop) { return nullptr; }
|
char* GetBase(char**) { return nullptr; }
|
||||||
void SetOutputPtr(size_t op) { produced_ = op; }
|
void SetOutputPtr(size_t op) { produced_ = op; }
|
||||||
inline bool CheckLength() const { return expected_ == produced_; }
|
inline bool CheckLength() const { return expected_ == produced_; }
|
||||||
inline bool Append(const char* ip, size_t len, size_t* produced) {
|
inline bool Append(const char* ip, size_t len, size_t* produced) {
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ static bool Compress(const char* input, size_t input_size, CompressorType comp,
|
|||||||
|
|
||||||
#ifdef LZ4_VERSION_NUMBER
|
#ifdef LZ4_VERSION_NUMBER
|
||||||
case LZ4: {
|
case LZ4: {
|
||||||
lzo_uint destlen = compressed->size();
|
int destlen = compressed->size();
|
||||||
destlen = LZ4_compress_default(input, string_as_array(compressed),
|
destlen = LZ4_compress_default(input, string_as_array(compressed),
|
||||||
input_size, destlen);
|
input_size, destlen);
|
||||||
CHECK(destlen != 0);
|
CHECK(destlen != 0);
|
||||||
@@ -268,8 +268,7 @@ static bool Uncompress(const std::string& compressed, CompressorType comp,
|
|||||||
#ifdef LZ4_VERSION_NUMBER
|
#ifdef LZ4_VERSION_NUMBER
|
||||||
case LZ4: {
|
case LZ4: {
|
||||||
output->resize(size);
|
output->resize(size);
|
||||||
ZLib zlib;
|
int destlen = output->size();
|
||||||
uLongf destlen = output->size();
|
|
||||||
destlen = LZ4_decompress_safe(compressed.data(), string_as_array(output),
|
destlen = LZ4_decompress_safe(compressed.data(), string_as_array(output),
|
||||||
compressed.size(), destlen);
|
compressed.size(), destlen);
|
||||||
CHECK(destlen != 0);
|
CHECK(destlen != 0);
|
||||||
@@ -1328,13 +1327,13 @@ struct SourceFiles {
|
|||||||
size_t max_size = 0;
|
size_t max_size = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void BM_UFlatMedley(testing::benchmark::State& state) {
|
static void BM_UFlatMedley(int iters, int) {
|
||||||
static const SourceFiles* const source = new SourceFiles();
|
static const SourceFiles* const source = new SourceFiles();
|
||||||
|
|
||||||
std::vector<char> dst(source->max_size);
|
std::vector<char> dst(source->max_size);
|
||||||
|
|
||||||
size_t processed = 0;
|
size_t processed = 0;
|
||||||
for (auto s : state) {
|
while (iters-- > 0) {
|
||||||
for (int i = 0; i < SourceFiles::kFiles; i++) {
|
for (int i = 0; i < SourceFiles::kFiles; i++) {
|
||||||
CHECK(snappy::RawUncompress(source->zcontents[i].data(),
|
CHECK(snappy::RawUncompress(source->zcontents[i].data(),
|
||||||
source->zcontents[i].size(), dst.data()));
|
source->zcontents[i].size(), dst.data()));
|
||||||
@@ -1368,11 +1367,11 @@ static void BM_UValidate(int iters, int arg) {
|
|||||||
}
|
}
|
||||||
BENCHMARK(BM_UValidate)->DenseRange(0, ARRAYSIZE(files) - 1);
|
BENCHMARK(BM_UValidate)->DenseRange(0, ARRAYSIZE(files) - 1);
|
||||||
|
|
||||||
static void BM_UValidateMedley(testing::benchmark::State& state) {
|
static void BM_UValidateMedley(int iters, int) {
|
||||||
static const SourceFiles* const source = new SourceFiles();
|
static const SourceFiles* const source = new SourceFiles();
|
||||||
|
|
||||||
size_t processed = 0;
|
size_t processed = 0;
|
||||||
for (auto s : state) {
|
while (iters-- > 0) {
|
||||||
for (int i = 0; i < SourceFiles::kFiles; i++) {
|
for (int i = 0; i < SourceFiles::kFiles; i++) {
|
||||||
CHECK(snappy::IsValidCompressedBuffer(source->zcontents[i].data(),
|
CHECK(snappy::IsValidCompressedBuffer(source->zcontents[i].data(),
|
||||||
source->zcontents[i].size()));
|
source->zcontents[i].size()));
|
||||||
|
|||||||
Reference in New Issue
Block a user