From 6e31fc621ed71b8cfa52c584a5e2f2831326bea3 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 9 Mar 2015 11:46:24 +1100 Subject: [PATCH] Cache the chunk bytes value to avoid setting it on each read_header call --- lrzip_private.h | 1 + runzip.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lrzip_private.h b/lrzip_private.h index 32648f8..d5cad4c 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -444,6 +444,7 @@ struct rzip_control { void (*log_cb)(void *data, unsigned int level, unsigned int line, const char *file, const char *func, const char *format, va_list); void *log_data; + char chunk_bytes; struct sliding_buffer sb; void (*do_mcpy)(rzip_control *, unsigned char *, i64, i64); void (*next_tag)(rzip_control *, struct rzip_state *, i64, tag *); diff --git a/runzip.c b/runzip.c index 20e54ea..0a0e630 100644 --- a/runzip.c +++ b/runzip.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2006-2012 Con Kolivas + Copyright (C) 2006-2015 Con Kolivas Copyright (C) 1998-2003 Andrew Tridgell This program is free software; you can redistribute it and/or modify @@ -139,16 +139,12 @@ static i64 seekto_fdinend(rzip_control *control) static i64 read_header(rzip_control *control, void *ss, uchar *head) { - int chunk_bytes = 2; bool err = false; - /* All chunks were unnecessarily encoded 8 bytes wide version 0.4x */ - if (control->major_version == 0 && control->minor_version == 4) - chunk_bytes = 8; *head = read_u8(control, ss, 0, &err); if (err) return -1; - return read_vchars(control, ss, 0, chunk_bytes); + return read_vchars(control, ss, 0, control->chunk_bytes); } static i64 unzip_literal(rzip_control *control, void *ss, i64 len, uint32 *cksum) @@ -309,6 +305,12 @@ static i64 runzip_chunk(rzip_control *control, int fd_in, i64 expected_size, i64 if (unlikely(!ss)) failure_return(("Failed to open_stream_in in runzip_chunk\n"), -1); + /* All chunks were unnecessarily encoded 8 bytes wide version 0.4x */ + if (control->major_version == 0 && control->minor_version == 4) + control->chunk_bytes = 8; + else + control->chunk_bytes = 2; + while ((len = read_header(control, ss, &head)) || head) { i64 u; if (unlikely(len == -1))