From cb7b0dd339264b368a799acff377966b8bad6f65 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Sun, 8 Mar 2015 00:59:05 +1100 Subject: [PATCH] Make full_tag a pointer allowing us to avoid a function call for get_sb --- lrzip_private.h | 1 + rzip.c | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lrzip_private.h b/lrzip_private.h index d7d71cb..2d80033 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -435,6 +435,7 @@ struct rzip_control { uchar *(*get_sb)(rzip_control *control, i64 p); void (*do_mcpy)(rzip_control *, unsigned char *, i64, i64); void (*next_tag)(rzip_control *, struct rzip_state *, i64, tag *); + tag (*full_tag)(rzip_control *, struct rzip_state *, i64); }; struct stream { diff --git a/rzip.c b/rzip.c index 7838e5b..1045735 100644 --- a/rzip.c +++ b/rzip.c @@ -443,14 +443,27 @@ static void sliding_next_tag(rzip_control *control, struct rzip_state *st, i64 p *t ^= st->hash_index[*u]; } -static inline tag full_tag(rzip_control *control, struct rzip_state *st, i64 p) +static tag single_full_tag(rzip_control *control, struct rzip_state *st, i64 p) +{ + tag ret = 0; + int i; + uchar u; + + for (i = 0; i < MINIMUM_MATCH; i++) { + u = control->sb.buf_low[p + i]; + ret ^= st->hash_index[u]; + } + return ret; +} + +static tag sliding_full_tag(rzip_control *control, struct rzip_state *st, i64 p) { tag ret = 0; int i; uchar *u; for (i = 0; i < MINIMUM_MATCH; i++) { - u = control->get_sb(control, p + i); + u = sliding_get_sb(control, p + i); if (unlikely(!u)) return -1; ret ^= st->hash_index[*u]; @@ -625,7 +638,7 @@ static inline bool hash_search(rzip_control *control, struct rzip_state *st, current.ofs = 0; if (likely(end > 0)) { - t = full_tag(control, st, p); + t = control->full_tag(control, st, p); if (unlikely(t == -1)) return false; } @@ -690,7 +703,7 @@ static inline bool hash_search(rzip_control *control, struct rzip_state *st, st->last_match = current.p + current.len; current.p = p = st->last_match; current.len = 0; - t = full_tag(control, st, p); + t = control->full_tag(control, st, p); if (unlikely(t == -1)) return false; } @@ -1003,6 +1016,7 @@ bool rzip_fd(rzip_control *control, int fd_in, int fd_out) control->get_sb = single_get_sb; control->do_mcpy = single_mcpy; control->next_tag = &single_next_tag; + control->full_tag = &single_full_tag; while (!pass || len > 0 || (STDIN && !st->stdin_eof)) { double pct_base, pct_multiple; @@ -1073,6 +1087,7 @@ retry: control->get_sb = &sliding_get_sb; control->do_mcpy = &sliding_mcpy; control->next_tag = &sliding_next_tag; + control->full_tag = &sliding_full_tag; } } print_maxverbose("Succeeded in testing %lld sized mmap for rzip pre-processing\n", st->mmap_size);