[PATCH 1 of 2] bdiff: extract line record finalization to a macro
Gregory Szorc
gregory.szorc at gmail.com
Sun Nov 13 03:44:48 UTC 2016
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1479000183 28800
# Sat Nov 12 17:23:03 2016 -0800
# Node ID 99388e747e8f99c7bdcfd2592ed8fc45e885ee55
# Parent 74918cd12b496ab6c975c05a202b334e07ef33c3
bdiff: extract line record finalization to a macro
A subsequent patch will introduce a 2nd call site for this
functionality. It is a bit too much to duplicate. And this is in a
tight loop and we don't want to take the risk that an "inline"
function won't actually be inlined. So we define it is a macro.
diff --git a/mercurial/bdiff.c b/mercurial/bdiff.c
--- a/mercurial/bdiff.c
+++ b/mercurial/bdiff.c
@@ -21,6 +21,16 @@
#define ROL(v, n) ((v) << (n) | (v) >> (sizeof(v) * CHAR_BIT - (n)))
#define HASH(h, c) ((c) + ROL(h ,7))
+#define FINALIZELINE(l, hash, p, b) { \
+ l->hash = hash; \
+ hash = 0; \
+ l->len = p - b + 1; \
+ l->l = b; \
+ l->n = INT_MAX; \
+ l++; \
+ b = p + 1; \
+}
+
struct pos {
int pos, len;
};
@@ -51,13 +61,7 @@ int bdiff_splitlines(const char *a, ssiz
hash = HASH(hash, *p);
if (*p == '\n' || p == plast) {
- l->hash = hash;
- hash = 0;
- l->len = p - b + 1;
- l->l = b;
- l->n = INT_MAX;
- l++;
- b = p + 1;
+ FINALIZELINE(l, hash, p, b);
}
}
More information about the Mercurial-devel
mailing list