Compare commits

...

45 Commits

Author SHA1 Message Date
Danila Kutenin
c6d8c585dd Internal change
PiperOrigin-RevId: 623073126
2026-05-09 18:52:31 +00:00
Danila Kutenin
da1ea96391 Internal change
PiperOrigin-RevId: 622802698
2026-05-09 18:52:23 +00:00
Richard O'Grady
e1e7329dc7 Internal changes
PiperOrigin-RevId: 621907514
2026-05-09 18:52:12 +00:00
danilak-G
0212163f6e Merge pull request #234 from anthony-zy/rv_extractoffset
RISC-V: Optimize decompression with branchless AdvanceToNextTagRVOptimized +13.7%
2026-05-09 12:22:41 +01:00
danilak-G
0daaac5b07 Merge pull request #232 from anthony-zy/main
refactor: Align RISC-V implementation with AArch64 branchless mask extraction
2026-05-09 12:17:15 +01:00
danilak-G
70a0e1cbda Merge pull request #220 from yunfeizhou2025/upload
limit RISC-V FindMatchLength optimizations to 64-bit
2026-05-09 12:12:15 +01:00
anthony-zy
28590427a6 RISC-V: Optimize Snappy decompression tag advance (AdvanceToNextTagRVOptimized) for +4% throughput 2026-04-17 09:59:32 +08:00
郑紫阳10295048
77534271b3 refactor: Align RISC-V implementation with AArch64 branchless mask extraction 2026-04-15 10:33:35 +08:00
danilak-G
6281a07b7e Merge pull request #229 from UebelAndre/config
Move `//:config` to `implementation_deps` to prevent header collision
2026-03-06 22:30:42 +00:00
UebelAndre
4cb90917ee Move //:config to implementation_deps to prevent header collision 2026-03-06 11:47:10 -08:00
danilak-G
051dc4dc43 Merge pull request #228 from UebelAndre/bazel
Add Bazel 9 support
2026-03-03 16:49:56 +00:00
UebelAndre
07614b8308 Add Bazel 9 support 2026-02-28 12:38:26 -08:00
danilak-G
da459b5263 Create COPYING.notestdata
This file is created for those who do not distribute testdata as it has different licenses, useful for some of our customers
2026-01-21 10:12:49 +00:00
Zhou Yunfei
6484508ffb limit RISC-V FindMatchLength optimizations to 64-bit
Add `__riscv_xlen == 64` check to ensure the optimized FindMatchLength
routine is only enabled on 64-bit RISC-V platforms.

Signed-off-by: Zhou Yunfei <xdzyf2012@gmail.com>
2025-12-12 14:01:42 +08:00
danilak-G
25e52c58fb Merge pull request #214 from anthony-zy/add_zbb_check_macro
RISC-V: gate __builtin_ctzll behind Zbb to avoid 10 % slowdown
2025-11-20 12:13:53 +00:00
anthony-zy
a862a744b5 fix confic 2025-11-10 18:40:59 +08:00
anthony-zy
992fb9fcb0 Resolve merge conflicts 2025-11-10 18:39:54 +08:00
anthony-zy
c633c6bcb7 Resolve merge conflicts 2025-11-10 18:37:35 +08:00
anthony-zy
30dbdc2728 add zbb check macro 2025-11-10 18:31:13 +08:00
anthony-zy
727f5b3fc6 add zbb check macro 2025-11-10 10:37:19 +08:00
Danila Kutenin
cbea40d40c Fix an unused var warning for RISC-V 2025-10-20 13:34:53 +00:00
danilak-G
633cb9cbcb Merge pull request #213 from anthony-zy/add_rvv_optmized_memcopy64
feat(RISC-V): Add RVV-optimized implementation for memcopy64
2025-10-20 08:50:42 +01:00
anthony-zy
e92cb6ae8a Merge branch 'add_rvv_optmized_memcopy64' of https://github.com/anthony-zy/snappy into add_rvv_optmized_memcopy64 2025-10-20 10:20:21 +08:00
anthony-zy
2d6c8f17de Merge branch 'add_rvv_optmized_memcopy64' of https://github.com/anthony-zy/snappy into add_rvv_optmized_memcopy64 2025-10-20 10:19:39 +08:00
anthony-zy
b63569f403 Merge branch 'add_rvv_optmized_memcopy64' of https://github.com/anthony-zy/snappy into add_rvv_optmized_memcopy64 2025-10-20 09:53:37 +08:00
anthony-zy
9cc1596bf6 Merge branch 'add_rvv_optmized_memcopy64' of https://github.com/anthony-zy/snappy into add_rvv_optmized_memcopy64 2025-10-20 09:53:27 +08:00
anthony-zy
c098f689b8 Merge branch 'add_rvv_optmized_memcopy64' of https://github.com/anthony-zy/snappy into add_rvv_optmized_memcopy64 2025-10-17 17:53:04 +08:00
anthony-zy
6ab5882822 Merge branch 'add_rvv_optmized_memcopy64' of https://github.com/anthony-zy/snappy into add_rvv_optmized_memcopy64 2025-10-17 17:52:35 +08:00
anthony-zy
d457ac7380 Merge branch 'add_rvv_optmized_memcopy64' of https://github.com/anthony-zy/snappy into add_rvv_optmized_memcopy64 2025-10-17 10:29:45 +08:00
anthony-zy
9fd2b72c77 fix by some comments 2025-10-17 10:28:17 +08:00
anthony-zy
77a61a4927 Merge branch 'add_rvv_optmized_memcopy64' of https://github.com/anthony-zy/snappy into add_rvv_optmized_memcopy64 2025-10-17 10:21:26 +08:00
anthony-zy
c19d705ee1 Merge branch 'add_rvv_support' of https://github.com/anthony-zy/snappy into add_rvv_support 2025-10-17 10:20:57 +08:00
anthony-zy
2b8136579d Merge branch 'add_rvv_support' of https://github.com/anthony-zy/snappy into add_rvv_support 2025-09-12 11:07:09 +08:00
anthony-zy
c860cabbc5 Merge branch 'google:main' into add_rvv_support 2025-09-12 10:59:56 +08:00
anthony-zy
441032643f Merge branch 'google:main' into add_rvv_support 2025-09-05 16:02:38 +08:00
anthony-zy
27d8915d34 Merge branch 'add_rvv_support' of https://github.com/anthony-zy/snappy into add_rvv_support 2025-09-05 16:00:09 +08:00
anthony-zy
eb8d19fc1e Merge branch 'add_rvv_support' of https://github.com/anthony-zy/snappy into add_rvv_support 2025-09-05 15:59:29 +08:00
anthony-zy
0f989a2a97 Merge branch 'add_rvv_support' of https://github.com/anthony-zy/snappy into add_rvv_support 2025-08-28 20:42:49 +08:00
anthony-zy
802ef73aed add RVV support and optmized uncompress speed 2025-08-28 20:42:13 +08:00
anthony-zy
1f6ba69d67 add RVV support and optimized uncompress speed 2025-08-28 20:11:39 +08:00
anthony-zy
758804a4bc Use high-performance FindMatchLength to Optimize Snappy compression speed For RISC-V[skip ci] 2025-08-26 20:51:45 +08:00
danilak-G
6f99459b5b Merge pull request #208 from wanghan-sanechips/riscv-benchmark-fix
build: Update benchmark submodule for RISC-V
2025-07-29 09:45:06 +01:00
danilak-G
4793b4d004 Merge pull request #210 from anthony-zy/rv_findmatchlenght
Use high-performance FindMatchLength to Optimize Snappy compression s…
2025-07-29 09:44:35 +01:00
anthony-zy
1d88de7de8 Use high-performance FindMatchLength to Optimize Snappy compression speed For RISC-V[skip ci] 2025-07-29 14:08:43 +08:00
wanghan
b68435f083 build: Update benchmark submodule for RISC-V
- Pins to b20cea67 to fix illegal instruction
- Verified on openEuler RISC-V
2025-07-28 18:23:35 +08:00
14 changed files with 53 additions and 158 deletions

View File

@@ -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
View File

@@ -6,5 +6,4 @@
# Build directory. # Build directory.
build/ build/
/bazel-* /bazel-*
MODULE.bazel.lock
out/ out/

View File

@@ -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",
], ],
) )

View File

@@ -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)

View File

@@ -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
View File

@@ -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

View File

@@ -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

View File

View File

@@ -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);

View File

@@ -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

View File

@@ -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);
} }
} }

View File

@@ -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());

View File

@@ -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);