mirror of https://github.com/google/snappy.git
parent
7ffaf77cf4
commit
0b990db2b8
83
snappy.cc
83
snappy.cc
|
@ -26,9 +26,9 @@
|
|||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "snappy.h"
|
||||
#include "snappy-internal.h"
|
||||
#include "snappy-sinksource.h"
|
||||
#include "snappy.h"
|
||||
|
||||
#if !defined(SNAPPY_HAVE_SSSE3)
|
||||
// __SSSE3__ is defined by GCC and Clang. Visual Studio doesn't target SIMD
|
||||
|
@ -244,8 +244,8 @@ inline char* IncrementalCopy(const char* src, char* op, char* const op_limit,
|
|||
// in-place, we avoid the penalty.
|
||||
if (SNAPPY_PREDICT_TRUE(op <= buf_limit - 16)) {
|
||||
const __m128i shuffle_mask = _mm_load_si128(
|
||||
reinterpret_cast<const __m128i*>(pshufb_fill_patterns)
|
||||
+ pattern_size - 1);
|
||||
reinterpret_cast<const __m128i*>(pshufb_fill_patterns) +
|
||||
pattern_size - 1);
|
||||
const __m128i pattern = _mm_shuffle_epi8(
|
||||
_mm_loadl_epi64(reinterpret_cast<const __m128i*>(src)), shuffle_mask);
|
||||
// Uninitialized bytes are masked out by the shuffle mask.
|
||||
|
@ -324,8 +324,7 @@ inline char* IncrementalCopy(const char* src, char* op, char* const op_limit,
|
|||
UnalignedCopy64(src, op);
|
||||
UnalignedCopy64(src + 8, op + 8);
|
||||
}
|
||||
if (op >= op_limit)
|
||||
return op_limit;
|
||||
if (op >= op_limit) return op_limit;
|
||||
|
||||
// We only take this branch if we didn't have enough slop and we can do a
|
||||
// single 8 byte copy.
|
||||
|
@ -340,9 +339,7 @@ inline char* IncrementalCopy(const char* src, char* op, char* const op_limit,
|
|||
} // namespace
|
||||
|
||||
template <bool allow_fast_path>
|
||||
static inline char* EmitLiteral(char* op,
|
||||
const char* literal,
|
||||
int len) {
|
||||
static inline char* EmitLiteral(char* op, const char* literal, int len) {
|
||||
// The vast majority of copies are below 16 bytes, for which a
|
||||
// call to std::memcpy() is overkill. This fast path can sometimes
|
||||
// copy up to 15 bytes too much, but that is okay in the
|
||||
|
@ -507,11 +504,8 @@ uint16_t* WorkingMemory::GetHashTable(size_t fragment_size,
|
|||
// Returns an "end" pointer into "op" buffer.
|
||||
// "end - op" is the compressed size of "input".
|
||||
namespace internal {
|
||||
char* CompressFragment(const char* input,
|
||||
size_t input_size,
|
||||
char* op,
|
||||
uint16_t* table,
|
||||
const int table_size) {
|
||||
char* CompressFragment(const char* input, size_t input_size, char* op,
|
||||
uint16_t* table, const int table_size) {
|
||||
// "ip" is the input pointer, and "op" is the output pointer.
|
||||
const char* ip = input;
|
||||
assert(input_size <= kBlockSize);
|
||||
|
@ -796,12 +790,7 @@ class SnappyDecompressor {
|
|||
|
||||
public:
|
||||
explicit SnappyDecompressor(Source* reader)
|
||||
: reader_(reader),
|
||||
ip_(NULL),
|
||||
ip_limit_(NULL),
|
||||
peeked_(0),
|
||||
eof_(false) {
|
||||
}
|
||||
: reader_(reader), ip_(NULL), ip_limit_(NULL), peeked_(0), eof_(false) {}
|
||||
|
||||
~SnappyDecompressor() {
|
||||
// Advance past any bytes we peeked at from the reader
|
||||
|
@ -809,9 +798,7 @@ class SnappyDecompressor {
|
|||
}
|
||||
|
||||
// Returns true iff we have hit the end of the input without an error.
|
||||
bool eof() const {
|
||||
return eof_;
|
||||
}
|
||||
bool eof() const { return eof_; }
|
||||
|
||||
// Read the uncompressed length stored at the start of the compressed data.
|
||||
// On success, stores the length in *result and returns true.
|
||||
|
@ -845,7 +832,8 @@ class SnappyDecompressor {
|
|||
#if defined(__GNUC__) && defined(__x86_64__)
|
||||
__attribute__((aligned(32)))
|
||||
#endif
|
||||
void DecompressAllTags(Writer* writer) {
|
||||
void
|
||||
DecompressAllTags(Writer* writer) {
|
||||
const char* ip = ip_;
|
||||
ResetLimit(ip);
|
||||
auto op = writer->GetOutputPtr();
|
||||
|
@ -1022,8 +1010,7 @@ static bool InternalUncompress(Source* r, Writer* writer) {
|
|||
|
||||
template <typename Writer>
|
||||
static bool InternalUncompressAllTags(SnappyDecompressor* decompressor,
|
||||
Writer* writer,
|
||||
uint32_t compressed_len,
|
||||
Writer* writer, uint32_t compressed_len,
|
||||
uint32_t uncompressed_len) {
|
||||
Report("snappy_uncompress", compressed_len, uncompressed_len);
|
||||
|
||||
|
@ -1159,15 +1146,12 @@ class SnappyIOVecWriter {
|
|||
: nullptr),
|
||||
curr_iov_remaining_(iov_count ? iov->iov_len : 0),
|
||||
total_written_(0),
|
||||
output_limit_(-1) {}
|
||||
|
||||
inline void SetExpectedLength(size_t len) {
|
||||
output_limit_ = len;
|
||||
output_limit_(-1) {
|
||||
}
|
||||
|
||||
inline bool CheckLength() const {
|
||||
return total_written_ == output_limit_;
|
||||
}
|
||||
inline void SetExpectedLength(size_t len) { output_limit_ = len; }
|
||||
|
||||
inline bool CheckLength() const { return total_written_ == output_limit_; }
|
||||
|
||||
inline bool Append(const char* ip, size_t len, char**) {
|
||||
if (total_written_ + len > output_limit_) {
|
||||
|
@ -1338,9 +1322,7 @@ class SnappyArrayWriter {
|
|||
op_limit_min_slop_ = op_limit_ - std::min<size_t>(kSlopBytes - 1, len);
|
||||
}
|
||||
|
||||
inline bool CheckLength() const {
|
||||
return op_ == op_limit_;
|
||||
}
|
||||
inline bool CheckLength() const { return op_ == op_limit_; }
|
||||
|
||||
char* GetOutputPtr() { return op_; }
|
||||
void SetOutputPtr(char* op) { op_ = op; }
|
||||
|
@ -1430,14 +1412,10 @@ class SnappyDecompressionValidator {
|
|||
|
||||
public:
|
||||
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_; }
|
||||
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) {
|
||||
// TODO: Switch to [[maybe_unused]] when we can assume C++17.
|
||||
(void)ip;
|
||||
|
@ -1476,9 +1454,7 @@ bool IsValidCompressed(Source* compressed) {
|
|||
return InternalUncompress(compressed, &writer);
|
||||
}
|
||||
|
||||
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) {
|
||||
ByteArraySource reader(input, input_length);
|
||||
UncheckedByteArraySink writer(compressed);
|
||||
|
@ -1528,9 +1504,7 @@ class SnappyScatteredWriter {
|
|||
// kSlopBytes starting at op.
|
||||
char* op_limit_min_slop_;
|
||||
|
||||
inline size_t Size() const {
|
||||
return full_size_ + (op_ptr_ - op_base_);
|
||||
}
|
||||
inline size_t Size() const { return full_size_ + (op_ptr_ - op_base_); }
|
||||
|
||||
bool SlowAppend(const char* ip, size_t len);
|
||||
bool SlowAppendFromSelf(size_t offset, size_t len);
|
||||
|
@ -1542,8 +1516,7 @@ class SnappyScatteredWriter {
|
|||
op_base_(NULL),
|
||||
op_ptr_(NULL),
|
||||
op_limit_(NULL),
|
||||
op_limit_min_slop_(NULL) {
|
||||
}
|
||||
op_limit_min_slop_(NULL) {}
|
||||
char* GetOutputPtr() { return op_ptr_; }
|
||||
void SetOutputPtr(char* op) { op_ptr_ = op; }
|
||||
|
||||
|
@ -1552,14 +1525,10 @@ class SnappyScatteredWriter {
|
|||
expected_ = len;
|
||||
}
|
||||
|
||||
inline bool CheckLength() const {
|
||||
return Size() == expected_;
|
||||
}
|
||||
inline bool CheckLength() const { return Size() == expected_; }
|
||||
|
||||
// Return the number of bytes actually uncompressed so far
|
||||
inline size_t Produced() const {
|
||||
return Size();
|
||||
}
|
||||
inline size_t Produced() const { return Size(); }
|
||||
|
||||
inline bool Append(const char* ip, size_t len, char** op_p) {
|
||||
char* op = *op_p;
|
||||
|
@ -1751,8 +1720,8 @@ bool Uncompress(Source* compressed, Sink* uncompressed) {
|
|||
|
||||
char c;
|
||||
size_t allocated_size;
|
||||
char* buf = uncompressed->GetAppendBufferVariable(
|
||||
1, uncompressed_len, &c, 1, &allocated_size);
|
||||
char* buf = uncompressed->GetAppendBufferVariable(1, uncompressed_len, &c, 1,
|
||||
&allocated_size);
|
||||
|
||||
const size_t compressed_len = compressed->Available();
|
||||
// If we can get a flat buffer, then use it, otherwise do block by block
|
||||
|
|
Loading…
Reference in New Issue