Fix an incorrect analysis / comment in the "pattern doubling" code.
This should have a miniscule positive effect on performance; the main idea of the CL is just to fix the incorrect comment.
This commit is contained in:
19
snappy.cc
19
snappy.cc
@@ -152,7 +152,7 @@ inline char* IncrementalCopy(const char* src, char* op, char* const op_limit,
|
|||||||
assert(op <= op_limit);
|
assert(op <= op_limit);
|
||||||
assert(op_limit <= buf_limit);
|
assert(op_limit <= buf_limit);
|
||||||
// NOTE: The compressor always emits 4 <= len <= 64. It is ok to assume that
|
// NOTE: The compressor always emits 4 <= len <= 64. It is ok to assume that
|
||||||
// to optimize this function but we have to also handle these cases in case
|
// to optimize this function but we have to also handle other cases in case
|
||||||
// the input does not satisfy these conditions.
|
// the input does not satisfy these conditions.
|
||||||
|
|
||||||
size_t pattern_size = op - src;
|
size_t pattern_size = op - src;
|
||||||
@@ -182,16 +182,13 @@ inline char* IncrementalCopy(const char* src, char* op, char* const op_limit,
|
|||||||
|
|
||||||
// Handle the uncommon case where pattern is less than 8 bytes.
|
// Handle the uncommon case where pattern is less than 8 bytes.
|
||||||
if (SNAPPY_PREDICT_FALSE(pattern_size < 8)) {
|
if (SNAPPY_PREDICT_FALSE(pattern_size < 8)) {
|
||||||
// Expand pattern to at least 8 bytes. The worse case scenario in terms of
|
// If plenty of buffer space remains, expand the pattern to at least 8
|
||||||
// buffer usage is when the pattern is size 3. ^ is the original position
|
// bytes. The way the following loop is written, we need 8 bytes of buffer
|
||||||
// of op. x are irrelevant bytes copied by the last UnalignedCopy64.
|
// space if pattern_size >= 4, 11 bytes if pattern_size is 1 or 3, and 10
|
||||||
//
|
// bytes if pattern_size is 2. Precisely encoding that is probably not
|
||||||
// abc
|
// worthwhile; instead, invoke the slow path if we cannot write 11 bytes
|
||||||
// abcabcxxxxx
|
// (because 11 are required in the worst case).
|
||||||
// abcabcabcabcxxxxx
|
if (SNAPPY_PREDICT_TRUE(op <= buf_limit - 11)) {
|
||||||
// ^
|
|
||||||
// The last x is 14 bytes after ^.
|
|
||||||
if (SNAPPY_PREDICT_TRUE(op <= buf_limit - 14)) {
|
|
||||||
while (pattern_size < 8) {
|
while (pattern_size < 8) {
|
||||||
UnalignedCopy64(src, op);
|
UnalignedCopy64(src, op);
|
||||||
op += pattern_size;
|
op += pattern_size;
|
||||||
|
|||||||
Reference in New Issue
Block a user