Compare commits
45 Commits
sylpheed-c
...
c6d8c585dd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6d8c585dd | ||
|
|
da1ea96391 | ||
|
|
e1e7329dc7 | ||
|
|
0212163f6e | ||
|
|
0daaac5b07 | ||
|
|
70a0e1cbda | ||
|
|
28590427a6 | ||
|
|
77534271b3 | ||
|
|
6281a07b7e | ||
|
|
4cb90917ee | ||
|
|
051dc4dc43 | ||
|
|
07614b8308 | ||
|
|
da459b5263 | ||
|
|
6484508ffb | ||
|
|
25e52c58fb | ||
|
|
a862a744b5 | ||
|
|
992fb9fcb0 | ||
|
|
c633c6bcb7 | ||
|
|
30dbdc2728 | ||
|
|
727f5b3fc6 | ||
|
|
cbea40d40c | ||
|
|
633cb9cbcb | ||
|
|
e92cb6ae8a | ||
|
|
2d6c8f17de | ||
|
|
b63569f403 | ||
|
|
9cc1596bf6 | ||
|
|
c098f689b8 | ||
|
|
6ab5882822 | ||
|
|
d457ac7380 | ||
|
|
9fd2b72c77 | ||
|
|
77a61a4927 | ||
|
|
c19d705ee1 | ||
|
|
2b8136579d | ||
|
|
c860cabbc5 | ||
|
|
441032643f | ||
|
|
27d8915d34 | ||
|
|
eb8d19fc1e | ||
|
|
0f989a2a97 | ||
|
|
802ef73aed | ||
|
|
1f6ba69d67 | ||
|
|
758804a4bc | ||
|
|
6f99459b5b | ||
|
|
4793b4d004 | ||
|
|
1d88de7de8 | ||
|
|
b68435f083 |
2
.bazelrc
2
.bazelrc
@@ -1,4 +1,2 @@
|
|||||||
# googletest requires C++14 or above
|
# googletest requires C++14 or above
|
||||||
build --cxxopt='-std=c++17'
|
build --cxxopt='-std=c++17'
|
||||||
# Enable Bzlmod for every Bazel command
|
|
||||||
common --enable_bzlmod
|
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,5 +6,4 @@
|
|||||||
# Build directory.
|
# Build directory.
|
||||||
build/
|
build/
|
||||||
/bazel-*
|
/bazel-*
|
||||||
MODULE.bazel.lock
|
|
||||||
out/
|
out/
|
||||||
|
|||||||
17
BUILD.bazel
17
BUILD.bazel
@@ -30,7 +30,7 @@ package(default_visibility = ["//visibility:public"])
|
|||||||
|
|
||||||
licenses(["notice"])
|
licenses(["notice"])
|
||||||
|
|
||||||
SNAPPY_VERSION = (1, 2, 2)
|
SNAPPY_VERSION = (1, 1, 10)
|
||||||
|
|
||||||
config_setting(
|
config_setting(
|
||||||
name = "windows",
|
name = "windows",
|
||||||
@@ -40,7 +40,7 @@ config_setting(
|
|||||||
cc_library(
|
cc_library(
|
||||||
name = "config",
|
name = "config",
|
||||||
hdrs = ["config.h"],
|
hdrs = ["config.h"],
|
||||||
defines = ["HAVE_CONFIG_H"],
|
defines = ["HAVE_CONFIG_H"]
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
@@ -70,11 +70,10 @@ cc_library(
|
|||||||
"snappy-sinksource.h",
|
"snappy-sinksource.h",
|
||||||
],
|
],
|
||||||
copts = select({
|
copts = select({
|
||||||
":windows": [],
|
":windows": [],
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
"-Wno-sign-compare",
|
"-Wno-sign-compare",
|
||||||
],
|
]}),
|
||||||
}),
|
|
||||||
deps = [
|
deps = [
|
||||||
":config",
|
":config",
|
||||||
":snappy-stubs-internal",
|
":snappy-stubs-internal",
|
||||||
@@ -115,7 +114,7 @@ cc_test(
|
|||||||
deps = [
|
deps = [
|
||||||
":snappy",
|
":snappy",
|
||||||
":snappy-test",
|
":snappy-test",
|
||||||
"@com_google_benchmark//:benchmark_main",
|
"//third_party/benchmark:benchmark_main",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -128,7 +127,7 @@ cc_test(
|
|||||||
deps = [
|
deps = [
|
||||||
":snappy",
|
":snappy",
|
||||||
":snappy-test",
|
":snappy-test",
|
||||||
"@com_google_googletest//:gtest_main",
|
"//third_party/googletest:gtest_main",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@
|
|||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.1)
|
||||||
project(Snappy VERSION 1.2.2 LANGUAGES C CXX)
|
project(Snappy VERSION 1.1.10 LANGUAGES C CXX)
|
||||||
|
|
||||||
# C++ standard can be overridden when this is used as a sub-project.
|
# C++ standard can be overridden when this is used as a sub-project.
|
||||||
if(NOT CMAKE_CXX_STANDARD)
|
if(NOT CMAKE_CXX_STANDARD)
|
||||||
@@ -38,7 +38,7 @@ if(NOT CMAKE_CXX_STANDARD)
|
|||||||
endif(NOT CMAKE_CXX_STANDARD)
|
endif(NOT CMAKE_CXX_STANDARD)
|
||||||
|
|
||||||
# https://github.com/izenecloud/cmake/blob/master/SetCompilerWarningAll.cmake
|
# https://github.com/izenecloud/cmake/blob/master/SetCompilerWarningAll.cmake
|
||||||
if(MSVC)
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
# Use the highest warning level for Visual Studio.
|
# Use the highest warning level for Visual Studio.
|
||||||
set(CMAKE_CXX_WARNING_LEVEL 4)
|
set(CMAKE_CXX_WARNING_LEVEL 4)
|
||||||
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||||
@@ -55,7 +55,7 @@ if(MSVC)
|
|||||||
# Disable RTTI.
|
# Disable RTTI.
|
||||||
string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
|
||||||
else(MSVC)
|
else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
# Use -Wall for clang and gcc.
|
# Use -Wall for clang and gcc.
|
||||||
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
|
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||||
@@ -85,7 +85,7 @@ else(MSVC)
|
|||||||
# Disable RTTI.
|
# Disable RTTI.
|
||||||
string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
|
||||||
endif(MSVC)
|
endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
|
|
||||||
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make
|
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make
|
||||||
# it prominent in the GUI.
|
# it prominent in the GUI.
|
||||||
@@ -206,13 +206,10 @@ int main() {
|
|||||||
|
|
||||||
check_cxx_source_compiles("
|
check_cxx_source_compiles("
|
||||||
#include <arm_neon.h>
|
#include <arm_neon.h>
|
||||||
#include <stdint.h>
|
|
||||||
int main() {
|
int main() {
|
||||||
uint8_t val = 3, dup[8];
|
uint8_t val = 3, dup[8];
|
||||||
uint8x16_t v1 = vld1q_dup_u8(&val);
|
uint8x16_t v = vld1q_dup_u8(&val);
|
||||||
uint8x16_t v2 = vqtbl1q_u8(v1, v1);
|
vst1q_u8(dup, v);
|
||||||
vst1q_u8(dup, v1);
|
|
||||||
vst1q_u8(dup, v2);
|
|
||||||
return 0;
|
return 0;
|
||||||
}" SNAPPY_HAVE_NEON)
|
}" SNAPPY_HAVE_NEON)
|
||||||
|
|
||||||
@@ -261,7 +258,9 @@ target_sources(snappy
|
|||||||
"snappy-stubs-internal.cc"
|
"snappy-stubs-internal.cc"
|
||||||
"snappy.cc"
|
"snappy.cc"
|
||||||
"${PROJECT_BINARY_DIR}/config.h"
|
"${PROJECT_BINARY_DIR}/config.h"
|
||||||
PUBLIC
|
|
||||||
|
# Only CMake 3.3+ supports PUBLIC sources in targets exported by "install".
|
||||||
|
$<$<VERSION_GREATER:CMAKE_VERSION,3.2>:PUBLIC>
|
||||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/snappy-c.h>
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/snappy-c.h>
|
||||||
$<INSTALL_INTERFACE:include/snappy-c.h>
|
$<INSTALL_INTERFACE:include/snappy-c.h>
|
||||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/snappy-sinksource.h>
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/snappy-sinksource.h>
|
||||||
@@ -298,9 +297,6 @@ if(SNAPPY_BUILD_TESTS OR SNAPPY_BUILD_BENCHMARKS)
|
|||||||
|
|
||||||
# Test files include snappy-test.h, HAVE_CONFIG_H must be defined.
|
# Test files include snappy-test.h, HAVE_CONFIG_H must be defined.
|
||||||
target_compile_definitions(snappy_test_support PUBLIC -DHAVE_CONFIG_H)
|
target_compile_definitions(snappy_test_support PUBLIC -DHAVE_CONFIG_H)
|
||||||
if(BUILD_SHARED_LIBS)
|
|
||||||
set_target_properties(snappy_test_support PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
|
||||||
endif(BUILD_SHARED_LIBS)
|
|
||||||
|
|
||||||
target_link_libraries(snappy_test_support snappy)
|
target_link_libraries(snappy_test_support snappy)
|
||||||
|
|
||||||
|
|||||||
23
MODULE.bazel
23
MODULE.bazel
@@ -1,23 +0,0 @@
|
|||||||
module(
|
|
||||||
name = "snappy",
|
|
||||||
version = "1.2.2",
|
|
||||||
compatibility_level = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
bazel_dep(
|
|
||||||
name = "googletest",
|
|
||||||
version = "1.14.0.bcr.1",
|
|
||||||
dev_dependency = True,
|
|
||||||
repo_name = "com_google_googletest",
|
|
||||||
)
|
|
||||||
bazel_dep(
|
|
||||||
name = "google_benchmark",
|
|
||||||
version = "1.9.0",
|
|
||||||
dev_dependency = True,
|
|
||||||
repo_name = "com_google_benchmark",
|
|
||||||
)
|
|
||||||
|
|
||||||
bazel_dep(
|
|
||||||
name = "platforms",
|
|
||||||
version = "0.0.9",
|
|
||||||
)
|
|
||||||
15
NEWS
15
NEWS
@@ -1,18 +1,3 @@
|
|||||||
Snappy v1.2.2, Mar 26th 2025:
|
|
||||||
|
|
||||||
* We added a new compression level in v1.2.1 which compresses a bit
|
|
||||||
denser but slower. Decompression speed should be even faster with it.
|
|
||||||
|
|
||||||
* We fixed a very old issue of data corruption when compressed size
|
|
||||||
exceeds 4GB. This can happen when you compress data close to 4GB
|
|
||||||
and it's incompressible, for example, random data.
|
|
||||||
|
|
||||||
* Started to use minimum CMake 3.10 because older ones are not
|
|
||||||
planned to be supported.
|
|
||||||
|
|
||||||
* Various other small fixes and performance improvements (especially
|
|
||||||
for clang).
|
|
||||||
|
|
||||||
Snappy v1.1.10, Mar 8th 2023:
|
Snappy v1.1.10, Mar 8th 2023:
|
||||||
|
|
||||||
* Performance improvements
|
* Performance improvements
|
||||||
|
|||||||
@@ -140,10 +140,10 @@ explicitly supports the following:
|
|||||||
1. C++11
|
1. C++11
|
||||||
2. Clang (gcc and MSVC are best-effort).
|
2. Clang (gcc and MSVC are best-effort).
|
||||||
3. Low level optimizations (e.g. assembly or equivalent intrinsics) for:
|
3. Low level optimizations (e.g. assembly or equivalent intrinsics) for:
|
||||||
- [x86](https://en.wikipedia.org/wiki/X86)
|
1. [x86](https://en.wikipedia.org/wiki/X86)
|
||||||
- [x86-64](https://en.wikipedia.org/wiki/X86-64)
|
2. [x86-64](https://en.wikipedia.org/wiki/X86-64)
|
||||||
- ARMv7 (32-bit)
|
3. ARMv7 (32-bit)
|
||||||
- ARMv8 (AArch64)
|
4. ARMv8 (AArch64)
|
||||||
4. Supports only the Snappy compression scheme as described in
|
4. Supports only the Snappy compression scheme as described in
|
||||||
[format_description.txt](format_description.txt).
|
[format_description.txt](format_description.txt).
|
||||||
5. CMake for building
|
5. CMake for building
|
||||||
|
|||||||
48
snappy.cc
48
snappy.cc
@@ -74,7 +74,6 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -960,8 +959,6 @@ emit_remainder:
|
|||||||
char* CompressFragmentDoubleHash(const char* input, size_t input_size, char* op,
|
char* CompressFragmentDoubleHash(const char* input, size_t input_size, char* op,
|
||||||
uint16_t* table, const int table_size,
|
uint16_t* table, const int table_size,
|
||||||
uint16_t* table2, const int table_size2) {
|
uint16_t* table2, const int table_size2) {
|
||||||
(void)table_size2;
|
|
||||||
assert(table_size == table_size2);
|
|
||||||
// "ip" is the input pointer, and "op" is the output pointer.
|
// "ip" is the input pointer, and "op" is the output pointer.
|
||||||
const char* ip = input;
|
const char* ip = input;
|
||||||
assert(input_size <= kBlockSize);
|
assert(input_size <= kBlockSize);
|
||||||
@@ -1499,7 +1496,7 @@ class SnappyDecompressor {
|
|||||||
// If ip < ip_limit_min_maxtaglen_ it's safe to read kMaxTagLength from
|
// If ip < ip_limit_min_maxtaglen_ it's safe to read kMaxTagLength from
|
||||||
// buffer.
|
// buffer.
|
||||||
const char* ip_limit_min_maxtaglen_;
|
const char* ip_limit_min_maxtaglen_;
|
||||||
uint64_t peeked_; // Bytes peeked from reader (need to skip)
|
uint32_t peeked_; // Bytes peeked from reader (need to skip)
|
||||||
bool eof_; // Hit end of input without an error?
|
bool eof_; // Hit end of input without an error?
|
||||||
char scratch_[kMaximumTagLength]; // See RefillTag().
|
char scratch_[kMaximumTagLength]; // See RefillTag().
|
||||||
|
|
||||||
@@ -1690,8 +1687,7 @@ constexpr uint32_t CalculateNeeded(uint8_t tag) {
|
|||||||
#if __cplusplus >= 201402L
|
#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) != static_cast<uint32_t>((char_table[i] >> 11)) + 1)
|
if (CalculateNeeded(i) != (char_table[i] >> 11) + 1) return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1727,7 +1723,7 @@ bool SnappyDecompressor::RefillTag() {
|
|||||||
assert(needed <= sizeof(scratch_));
|
assert(needed <= sizeof(scratch_));
|
||||||
|
|
||||||
// Read more bytes from reader if needed
|
// Read more bytes from reader if needed
|
||||||
uint64_t nbuf = ip_limit_ - ip;
|
uint32_t nbuf = ip_limit_ - ip;
|
||||||
if (nbuf < needed) {
|
if (nbuf < needed) {
|
||||||
// Stitch together bytes from ip and reader to form the word
|
// Stitch together bytes from ip and reader to form the word
|
||||||
// contents. We store the needed bytes in "scratch_". They
|
// contents. We store the needed bytes in "scratch_". They
|
||||||
@@ -1740,7 +1736,7 @@ bool SnappyDecompressor::RefillTag() {
|
|||||||
size_t length;
|
size_t length;
|
||||||
const char* src = reader_->Peek(&length);
|
const char* src = reader_->Peek(&length);
|
||||||
if (length == 0) return false;
|
if (length == 0) return false;
|
||||||
uint64_t to_add = std::min<uint64_t>(needed - nbuf, length);
|
uint32_t to_add = std::min<uint32_t>(needed - nbuf, length);
|
||||||
std::memcpy(scratch_ + nbuf, src, to_add);
|
std::memcpy(scratch_ + nbuf, src, to_add);
|
||||||
nbuf += to_add;
|
nbuf += to_add;
|
||||||
reader_->Skip(to_add);
|
reader_->Skip(to_add);
|
||||||
@@ -1794,16 +1790,11 @@ bool GetUncompressedLength(Source* source, uint32_t* result) {
|
|||||||
return decompressor.ReadUncompressedLength(result);
|
return decompressor.ReadUncompressedLength(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Compress(Source* reader, Sink* writer) {
|
|
||||||
return Compress(reader, writer, CompressionOptions{});
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Compress(Source* reader, Sink* writer, CompressionOptions options) {
|
size_t Compress(Source* reader, Sink* writer, CompressionOptions options) {
|
||||||
assert(options.level == 1 || options.level == 2);
|
assert(options.level == 1 || options.level == 2);
|
||||||
int token = 0;
|
int token = 0;
|
||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
size_t N = reader->Available();
|
size_t N = reader->Available();
|
||||||
assert(N <= 0xFFFFFFFFu);
|
|
||||||
const size_t uncompressed_size = N;
|
const size_t uncompressed_size = N;
|
||||||
char ulength[Varint::kMax32];
|
char ulength[Varint::kMax32];
|
||||||
char* p = Varint::Encode32(ulength, N);
|
char* p = Varint::Encode32(ulength, N);
|
||||||
@@ -1895,16 +1886,16 @@ class SnappyIOVecReader : public Source {
|
|||||||
if (total_size > 0 && curr_size_remaining_ == 0) Advance();
|
if (total_size > 0 && curr_size_remaining_ == 0) Advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
~SnappyIOVecReader() override = default;
|
~SnappyIOVecReader() = default;
|
||||||
|
|
||||||
size_t Available() const override { return total_size_remaining_; }
|
size_t Available() const { return total_size_remaining_; }
|
||||||
|
|
||||||
const char* Peek(size_t* len) override {
|
const char* Peek(size_t* len) {
|
||||||
*len = curr_size_remaining_;
|
*len = curr_size_remaining_;
|
||||||
return curr_pos_;
|
return curr_pos_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skip(size_t n) override {
|
void Skip(size_t n) {
|
||||||
while (n >= curr_size_remaining_ && n > 0) {
|
while (n >= curr_size_remaining_ && n > 0) {
|
||||||
n -= curr_size_remaining_;
|
n -= curr_size_remaining_;
|
||||||
Advance();
|
Advance();
|
||||||
@@ -2305,12 +2296,6 @@ bool IsValidCompressed(Source* compressed) {
|
|||||||
return InternalUncompress(compressed, &writer);
|
return InternalUncompress(compressed, &writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawCompress(const char* input, size_t input_length, char* compressed,
|
|
||||||
size_t* compressed_length) {
|
|
||||||
RawCompress(input, input_length, compressed, compressed_length,
|
|
||||||
CompressionOptions{});
|
|
||||||
}
|
|
||||||
|
|
||||||
void RawCompress(const char* input, size_t input_length, char* compressed,
|
void RawCompress(const char* input, size_t input_length, char* compressed,
|
||||||
size_t* compressed_length, CompressionOptions options) {
|
size_t* compressed_length, CompressionOptions options) {
|
||||||
ByteArraySource reader(input, input_length);
|
ByteArraySource reader(input, input_length);
|
||||||
@@ -2321,12 +2306,6 @@ void RawCompress(const char* input, size_t input_length, char* compressed,
|
|||||||
*compressed_length = (writer.CurrentDestination() - compressed);
|
*compressed_length = (writer.CurrentDestination() - compressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
|
|
||||||
char* compressed, size_t* compressed_length) {
|
|
||||||
RawCompressFromIOVec(iov, uncompressed_length, compressed, compressed_length,
|
|
||||||
CompressionOptions{});
|
|
||||||
}
|
|
||||||
|
|
||||||
void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
|
void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
|
||||||
char* compressed, size_t* compressed_length,
|
char* compressed, size_t* compressed_length,
|
||||||
CompressionOptions options) {
|
CompressionOptions options) {
|
||||||
@@ -2338,11 +2317,6 @@ void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
|
|||||||
*compressed_length = writer.CurrentDestination() - compressed;
|
*compressed_length = writer.CurrentDestination() - compressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Compress(const char* input, size_t input_length,
|
|
||||||
std::string* compressed) {
|
|
||||||
return Compress(input, input_length, compressed, CompressionOptions{});
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Compress(const char* input, size_t input_length, std::string* compressed,
|
size_t Compress(const char* input, size_t input_length, std::string* compressed,
|
||||||
CompressionOptions options) {
|
CompressionOptions options) {
|
||||||
// Pre-grow the buffer to the max length of the compressed output
|
// Pre-grow the buffer to the max length of the compressed output
|
||||||
@@ -2355,11 +2329,6 @@ size_t Compress(const char* input, size_t input_length, std::string* compressed,
|
|||||||
return compressed_length;
|
return compressed_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
|
|
||||||
std::string* compressed) {
|
|
||||||
return CompressFromIOVec(iov, iov_cnt, compressed, CompressionOptions{});
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
|
size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
|
||||||
std::string* compressed, CompressionOptions options) {
|
std::string* compressed, CompressionOptions options) {
|
||||||
// Compute the number of bytes to be compressed.
|
// Compute the number of bytes to be compressed.
|
||||||
@@ -2564,6 +2533,7 @@ bool SnappyScatteredWriter<Allocator>::SlowAppendFromSelf(size_t offset,
|
|||||||
class SnappySinkAllocator {
|
class SnappySinkAllocator {
|
||||||
public:
|
public:
|
||||||
explicit SnappySinkAllocator(Sink* dest) : dest_(dest) {}
|
explicit SnappySinkAllocator(Sink* dest) : dest_(dest) {}
|
||||||
|
~SnappySinkAllocator() {}
|
||||||
|
|
||||||
char* Allocate(int size) {
|
char* Allocate(int size) {
|
||||||
Datablock block(new char[size], size);
|
Datablock block(new char[size], size);
|
||||||
|
|||||||
25
snappy.h
25
snappy.h
@@ -64,9 +64,6 @@ namespace snappy {
|
|||||||
// faster decompression speeds than snappy:1 and zstd:-3.
|
// faster decompression speeds than snappy:1 and zstd:-3.
|
||||||
int level = DefaultCompressionLevel();
|
int level = DefaultCompressionLevel();
|
||||||
|
|
||||||
constexpr CompressionOptions() = default;
|
|
||||||
constexpr CompressionOptions(int compression_level)
|
|
||||||
: level(compression_level) {}
|
|
||||||
static constexpr int MinCompressionLevel() { return 1; }
|
static constexpr int MinCompressionLevel() { return 1; }
|
||||||
static constexpr int MaxCompressionLevel() { return 2; }
|
static constexpr int MaxCompressionLevel() { return 2; }
|
||||||
static constexpr int DefaultCompressionLevel() { return 1; }
|
static constexpr int DefaultCompressionLevel() { return 1; }
|
||||||
@@ -78,10 +75,8 @@ namespace snappy {
|
|||||||
|
|
||||||
// Compress the bytes read from "*reader" and append to "*writer". Return the
|
// Compress the bytes read from "*reader" and append to "*writer". Return the
|
||||||
// number of bytes written.
|
// number of bytes written.
|
||||||
// First version is to preserve ABI.
|
|
||||||
size_t Compress(Source* reader, Sink* writer);
|
|
||||||
size_t Compress(Source* reader, Sink* writer,
|
size_t Compress(Source* reader, Sink* writer,
|
||||||
CompressionOptions options);
|
CompressionOptions options = {});
|
||||||
|
|
||||||
// Find the uncompressed length of the given stream, as given by the header.
|
// Find the uncompressed length of the given stream, as given by the header.
|
||||||
// Note that the true length could deviate from this; the stream could e.g.
|
// Note that the true length could deviate from this; the stream could e.g.
|
||||||
@@ -100,22 +95,16 @@ namespace snappy {
|
|||||||
// Original contents of *compressed are lost.
|
// Original contents of *compressed are lost.
|
||||||
//
|
//
|
||||||
// REQUIRES: "input[]" is not an alias of "*compressed".
|
// REQUIRES: "input[]" is not an alias of "*compressed".
|
||||||
// First version is to preserve ABI.
|
|
||||||
size_t Compress(const char* input, size_t input_length,
|
size_t Compress(const char* input, size_t input_length,
|
||||||
std::string* compressed);
|
std::string* compressed, CompressionOptions options = {});
|
||||||
size_t Compress(const char* input, size_t input_length,
|
|
||||||
std::string* compressed, CompressionOptions options);
|
|
||||||
|
|
||||||
// Same as `Compress` above but taking an `iovec` array as input. Note that
|
// Same as `Compress` above but taking an `iovec` array as input. Note that
|
||||||
// this function preprocesses the inputs to compute the sum of
|
// this function preprocesses the inputs to compute the sum of
|
||||||
// `iov[0..iov_cnt-1].iov_len` before reading. To avoid this, use
|
// `iov[0..iov_cnt-1].iov_len` before reading. To avoid this, use
|
||||||
// `RawCompressFromIOVec` below.
|
// `RawCompressFromIOVec` below.
|
||||||
// First version is to preserve ABI.
|
|
||||||
size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
|
|
||||||
std::string* compressed);
|
|
||||||
size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
|
size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
|
||||||
std::string* compressed,
|
std::string* compressed,
|
||||||
CompressionOptions options);
|
CompressionOptions options = {});
|
||||||
|
|
||||||
// Decompresses "compressed[0..compressed_length-1]" to "*uncompressed".
|
// Decompresses "compressed[0..compressed_length-1]" to "*uncompressed".
|
||||||
// Original contents of "*uncompressed" are lost.
|
// Original contents of "*uncompressed" are lost.
|
||||||
@@ -159,18 +148,14 @@ namespace snappy {
|
|||||||
// ... Process(output, output_length) ...
|
// ... Process(output, output_length) ...
|
||||||
// delete [] output;
|
// delete [] output;
|
||||||
void RawCompress(const char* input, size_t input_length, char* compressed,
|
void RawCompress(const char* input, size_t input_length, char* compressed,
|
||||||
size_t* compressed_length);
|
size_t* compressed_length, CompressionOptions options = {});
|
||||||
void RawCompress(const char* input, size_t input_length, char* compressed,
|
|
||||||
size_t* compressed_length, CompressionOptions options);
|
|
||||||
|
|
||||||
// Same as `RawCompress` above but taking an `iovec` array as input. Note that
|
// Same as `RawCompress` above but taking an `iovec` array as input. Note that
|
||||||
// `uncompressed_length` is the total number of bytes to be read from the
|
// `uncompressed_length` is the total number of bytes to be read from the
|
||||||
// elements of `iov` (_not_ the number of elements in `iov`).
|
// elements of `iov` (_not_ the number of elements in `iov`).
|
||||||
void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
|
|
||||||
char* compressed, size_t* compressed_length);
|
|
||||||
void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
|
void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
|
||||||
char* compressed, size_t* compressed_length,
|
char* compressed, size_t* compressed_length,
|
||||||
CompressionOptions options);
|
CompressionOptions options = {});
|
||||||
|
|
||||||
// Given data in "compressed[0..compressed_length-1]" generated by
|
// Given data in "compressed[0..compressed_length-1]" generated by
|
||||||
// calling the Snappy::Compress routine, this routine
|
// calling the Snappy::Compress routine, this routine
|
||||||
|
|||||||
@@ -31,10 +31,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "snappy-test.h"
|
||||||
|
|
||||||
#include "benchmark/benchmark.h"
|
#include "benchmark/benchmark.h"
|
||||||
|
|
||||||
#include "snappy-internal.h"
|
#include "snappy-internal.h"
|
||||||
#include "snappy-sinksource.h"
|
#include "snappy-sinksource.h"
|
||||||
#include "snappy-test.h"
|
|
||||||
#include "snappy.h"
|
#include "snappy.h"
|
||||||
#include "snappy_test_data.h"
|
#include "snappy_test_data.h"
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ namespace snappy {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void FilesAndLevels(benchmark::internal::Benchmark* benchmark) {
|
void FilesAndLevels(::testing::Benchmark* benchmark) {
|
||||||
for (int i = 0; i < ARRAYSIZE(kTestDataFiles); ++i) {
|
for (int i = 0; i < ARRAYSIZE(kTestDataFiles); ++i) {
|
||||||
for (int level = snappy::CompressionOptions::MinCompressionLevel();
|
for (int level = snappy::CompressionOptions::MinCompressionLevel();
|
||||||
level <= snappy::CompressionOptions::MaxCompressionLevel(); ++level) {
|
level <= snappy::CompressionOptions::MaxCompressionLevel(); ++level) {
|
||||||
@@ -62,9 +64,8 @@ void BM_UFlat(benchmark::State& state) {
|
|||||||
kTestDataFiles[file_index].size_limit);
|
kTestDataFiles[file_index].size_limit);
|
||||||
|
|
||||||
std::string zcontents;
|
std::string zcontents;
|
||||||
snappy::Compress(
|
snappy::Compress(contents.data(), contents.size(), &zcontents,
|
||||||
contents.data(), contents.size(), &zcontents,
|
snappy::CompressionOptions{.level = state.range(1)});
|
||||||
snappy::CompressionOptions{/*level=*/static_cast<int>(state.range(1))});
|
|
||||||
char* dst = new char[contents.size()];
|
char* dst = new char[contents.size()];
|
||||||
|
|
||||||
for (auto s : state) {
|
for (auto s : state) {
|
||||||
@@ -128,9 +129,8 @@ void BM_UValidate(benchmark::State& state) {
|
|||||||
kTestDataFiles[file_index].size_limit);
|
kTestDataFiles[file_index].size_limit);
|
||||||
|
|
||||||
std::string zcontents;
|
std::string zcontents;
|
||||||
snappy::Compress(
|
snappy::Compress(contents.data(), contents.size(), &zcontents,
|
||||||
contents.data(), contents.size(), &zcontents,
|
snappy::CompressionOptions{.level = state.range(1)});
|
||||||
snappy::CompressionOptions{/*level=*/static_cast<int>(state.range(1))});
|
|
||||||
|
|
||||||
for (auto s : state) {
|
for (auto s : state) {
|
||||||
CHECK(snappy::IsValidCompressedBuffer(zcontents.data(), zcontents.size()));
|
CHECK(snappy::IsValidCompressedBuffer(zcontents.data(), zcontents.size()));
|
||||||
@@ -193,7 +193,7 @@ void BM_UIOVecSource(benchmark::State& state) {
|
|||||||
size_t zsize = 0;
|
size_t zsize = 0;
|
||||||
for (auto s : state) {
|
for (auto s : state) {
|
||||||
snappy::RawCompressFromIOVec(iov, contents.size(), dst, &zsize,
|
snappy::RawCompressFromIOVec(iov, contents.size(), dst, &zsize,
|
||||||
snappy::CompressionOptions{/*level=*/level});
|
snappy::CompressionOptions{.level = level});
|
||||||
benchmark::DoNotOptimize(iov);
|
benchmark::DoNotOptimize(iov);
|
||||||
}
|
}
|
||||||
state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) *
|
state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) *
|
||||||
@@ -226,7 +226,7 @@ void BM_UIOVecSink(benchmark::State& state) {
|
|||||||
// Uncompress into an iovec containing ten entries.
|
// Uncompress into an iovec containing ten entries.
|
||||||
const int kNumEntries = 10;
|
const int kNumEntries = 10;
|
||||||
struct iovec iov[kNumEntries];
|
struct iovec iov[kNumEntries];
|
||||||
char* dst = new char[contents.size()];
|
char *dst = new char[contents.size()];
|
||||||
size_t used_so_far = 0;
|
size_t used_so_far = 0;
|
||||||
for (int i = 0; i < kNumEntries; ++i) {
|
for (int i = 0; i < kNumEntries; ++i) {
|
||||||
iov[i].iov_base = dst + used_so_far;
|
iov[i].iov_base = dst + used_so_far;
|
||||||
@@ -267,9 +267,8 @@ void BM_UFlatSink(benchmark::State& state) {
|
|||||||
kTestDataFiles[file_index].size_limit);
|
kTestDataFiles[file_index].size_limit);
|
||||||
|
|
||||||
std::string zcontents;
|
std::string zcontents;
|
||||||
snappy::Compress(
|
snappy::Compress(contents.data(), contents.size(), &zcontents,
|
||||||
contents.data(), contents.size(), &zcontents,
|
snappy::CompressionOptions{.level = state.range(1)});
|
||||||
snappy::CompressionOptions{/*level=*/static_cast<int>(state.range(1))});
|
|
||||||
char* dst = new char[contents.size()];
|
char* dst = new char[contents.size()];
|
||||||
|
|
||||||
for (auto s : state) {
|
for (auto s : state) {
|
||||||
@@ -305,7 +304,7 @@ void BM_ZFlat(benchmark::State& state) {
|
|||||||
size_t zsize = 0;
|
size_t zsize = 0;
|
||||||
for (auto s : state) {
|
for (auto s : state) {
|
||||||
snappy::RawCompress(contents.data(), contents.size(), dst, &zsize,
|
snappy::RawCompress(contents.data(), contents.size(), dst, &zsize,
|
||||||
snappy::CompressionOptions{/*level=*/level});
|
snappy::CompressionOptions{.level = level});
|
||||||
benchmark::DoNotOptimize(dst);
|
benchmark::DoNotOptimize(dst);
|
||||||
}
|
}
|
||||||
state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) *
|
state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) *
|
||||||
@@ -341,7 +340,7 @@ void BM_ZFlatAll(benchmark::State& state) {
|
|||||||
for (auto s : state) {
|
for (auto s : state) {
|
||||||
for (int i = 0; i < num_files; ++i) {
|
for (int i = 0; i < num_files; ++i) {
|
||||||
snappy::RawCompress(contents[i].data(), contents[i].size(), dst[i],
|
snappy::RawCompress(contents[i].data(), contents[i].size(), dst[i],
|
||||||
&zsize, snappy::CompressionOptions{/*level=*/level});
|
&zsize, snappy::CompressionOptions{.level = level});
|
||||||
benchmark::DoNotOptimize(dst);
|
benchmark::DoNotOptimize(dst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -378,7 +377,7 @@ void BM_ZFlatIncreasingTableSize(benchmark::State& state) {
|
|||||||
for (auto s : state) {
|
for (auto s : state) {
|
||||||
for (size_t i = 0; i < contents.size(); ++i) {
|
for (size_t i = 0; i < contents.size(); ++i) {
|
||||||
snappy::RawCompress(contents[i].data(), contents[i].size(), dst[i],
|
snappy::RawCompress(contents[i].data(), contents[i].size(), dst[i],
|
||||||
&zsize, snappy::CompressionOptions{/*level=*/level});
|
&zsize, snappy::CompressionOptions{.level = level});
|
||||||
benchmark::DoNotOptimize(dst);
|
benchmark::DoNotOptimize(dst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||||||
std::string compressed;
|
std::string compressed;
|
||||||
size_t compressed_size =
|
size_t compressed_size =
|
||||||
snappy::Compress(input.data(), input.size(), &compressed,
|
snappy::Compress(input.data(), input.size(), &compressed,
|
||||||
snappy::CompressionOptions{/*level=*/level});
|
snappy::CompressionOptions{.level = level});
|
||||||
|
|
||||||
(void)compressed_size; // Variable only used in debug builds.
|
(void)compressed_size; // Variable only used in debug builds.
|
||||||
assert(compressed_size == compressed.size());
|
assert(compressed_size == compressed.size());
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cinttypes>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <random>
|
#include <random>
|
||||||
@@ -485,18 +484,6 @@ TEST(Snappy, MaxBlowup) {
|
|||||||
Verify(input);
|
Verify(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue #201, when output is more than 4GB, we had a data corruption bug.
|
|
||||||
// We cannot run this test always because of CI constraints.
|
|
||||||
TEST(Snappy, DISABLED_MoreThan4GB) {
|
|
||||||
std::mt19937 rng;
|
|
||||||
std::uniform_int_distribution<int> uniform_byte(0, 255);
|
|
||||||
std::string input;
|
|
||||||
input.resize((1ull << 32) - 1);
|
|
||||||
for (uint64_t i = 0; i < ((1ull << 32) - 1); ++i)
|
|
||||||
input[i] = static_cast<char>(uniform_byte(rng));
|
|
||||||
Verify(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Snappy, RandomData) {
|
TEST(Snappy, RandomData) {
|
||||||
std::minstd_rand0 rng(snappy::GetFlag(FLAGS_test_random_seed));
|
std::minstd_rand0 rng(snappy::GetFlag(FLAGS_test_random_seed));
|
||||||
std::uniform_int_distribution<int> uniform_0_to_3(0, 3);
|
std::uniform_int_distribution<int> uniform_0_to_3(0, 3);
|
||||||
|
|||||||
2
third_party/benchmark
vendored
2
third_party/benchmark
vendored
Submodule third_party/benchmark updated: d572f47773...b20cea6741
Reference in New Issue
Block a user