Compress-Snappy

 view release on metacpan or  search on metacpan

src/csnappy.h  view on Meta::CPAN

 * REQUIRES: "input" is at most 32KiB long.
 * REQUIRES: "output" points to an array of memory that is at least
 * "csnappy_max_compressed_length(input_length)" in size.
 * REQUIRES: working_memory has (1 << workmem_bytes_power_of_two) bytes.
 * REQUIRES: 9 <= workmem_bytes_power_of_two <= 15.
 *
 * Returns an "end" pointer into "output" buffer.
 * "end - output" is the compressed size of "input".
 */
char*
csnappy_compress_fragment(
	const char *input,
	const uint32_t input_length,
	char *output,
	void *working_memory,
	const int workmem_bytes_power_of_two);

/*
 * REQUIRES: "compressed" must point to an area of memory that is at
 * least "csnappy_max_compressed_length(input_length)" bytes in length.
 * REQUIRES: working_memory has (1 << workmem_bytes_power_of_two) bytes.

src/csnappy_compress.c  view on Meta::CPAN

	while (s2 < s2_end && *s1++ == *s2++) /*nothing*/;
	return s2 - s2_start - 1;
}

static uint32_t hash(uint32_t v)
{
	return v * UINT32_C(0x1e35a7bd);
}

char*
csnappy_compress_fragment(
	const char *input,
	const uint32_t input_size,
	char *dst,
	void *working_memory,
	const int workmem_bytes_power_of_two)
{
	const uint8_t * const src_start = (const uint8_t *)input;
	const uint8_t * const src_end_minus4 = src_start + input_size - 4;
	const uint8_t *src = src_start, *done_upto = src_start, *match;
	uint8_t *op = (uint8_t *)dst;

src/csnappy_compress.c  view on Meta::CPAN

	DCHECK_GE(offset, 0);
	DCHECK_LE(offset, 4);
	return UNALIGNED_LOAD32(v + offset);
}

#endif /* !ARCH_K8 */


#define kInputMarginBytes 15
char*
csnappy_compress_fragment(
	const char *input,
	const uint32_t input_size,
	char *op,
	void *working_memory,
	const int workmem_bytes_power_of_two)
{
	const char *ip, *ip_end, *base_ip, *next_emit, *ip_limit, *next_ip,
			*candidate, *base;
	uint16_t *table = (uint16_t *)working_memory;
	EightBytesReference input_bytes;

src/csnappy_compress.c  view on Meta::CPAN


emit_remainder:
	/* Emit the remaining bytes as a literal */
	if (next_emit < ip_end)
		op = EmitLiteral(op, next_emit, ip_end - next_emit, 0);

	return op;
}
#endif /* !simple */
#if defined(__KERNEL__) && !defined(STATIC)
EXPORT_SYMBOL(csnappy_compress_fragment);
#endif

uint32_t __attribute__((const))
csnappy_max_compressed_length(uint32_t source_len)
{
	return 32 + source_len + source_len/6;
}
#if defined(__KERNEL__) && !defined(STATIC)
EXPORT_SYMBOL(csnappy_max_compressed_length);
#endif

src/csnappy_compress.c  view on Meta::CPAN

		num_to_read = min(input_length, (uint32_t)kBlockSize);
		workmem_size = workmem_bytes_power_of_two;
		if (unlikely(num_to_read < kBlockSize)) {
			for (workmem_size = 9;
			     workmem_size < workmem_bytes_power_of_two;
			     ++workmem_size) {
				if ((1 << (workmem_size-1)) >= num_to_read)
					break;
			}
		}
		p = csnappy_compress_fragment(
				input, num_to_read, compressed,
				working_memory, workmem_size);
		written += (p - compressed);
		compressed = p;
		input_length -= num_to_read;
		input += num_to_read;
	}
	*compressed_length = written;
}
#if defined(__KERNEL__) && !defined(STATIC)



( run in 2.224 seconds using v1.01-cache-2.11-cpan-364913b4093 )