Skip to content

Commit 41d9783

Browse files
phillipwoodgitster
authored andcommitted
xdiff: refactor xdl_hash_record()
Inline the check for whitespace flags so that the compiler can hoist it out of the loop in xdl_prepare_ctx(). This improves the performance by 8%. $ hyperfine --warmup=1 -L rev HEAD,HEAD^ --setup='git checkout {rev} -- :/ && make git' ': {rev}; GIT_CONFIG_GLOBAL=/dev/null ./git log --oneline --shortstat v2.0.0..v2.5.0' Benchmark 1: : HEAD; GIT_CONFIG_GLOBAL=/dev/null ./git log --oneline --shortstat v2.0.0..v2.5.0 Time (mean ± σ): 1.670 s ± 0.044 s [User: 1.473 s, System: 0.196 s] Range (min … max): 1.619 s … 1.754 s 10 runs Benchmark 2: : HEAD^; GIT_CONFIG_GLOBAL=/dev/null ./git log --oneline --shortstat v2.0.0..v2.5.0 Time (mean ± σ): 1.801 s ± 0.021 s [User: 1.605 s, System: 0.192 s] Range (min … max): 1.766 s … 1.831 s 10 runs Summary ': HEAD^; GIT_CONFIG_GLOBAL=/dev/null ./git log --oneline --shortstat v2.0.0..v2.5.0' ran 1.08 ± 0.03 times faster than ': HEAD^^; GIT_CONFIG_GLOBAL=/dev/null ./git log --oneline --shortstat v2.0.0..v2.5.0' Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e813a02 commit 41d9783

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

xdiff/xutils.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
249249
return 1;
250250
}
251251

252-
static unsigned long xdl_hash_record_with_whitespace(char const **data,
252+
unsigned long xdl_hash_record_with_whitespace(char const **data,
253253
char const *top, long flags) {
254254
unsigned long ha = 5381;
255255
char const *ptr = *data;
@@ -294,13 +294,10 @@ static unsigned long xdl_hash_record_with_whitespace(char const **data,
294294
return ha;
295295
}
296296

297-
unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
297+
unsigned long xdl_hash_record_verbatim(char const **data, char const *top) {
298298
unsigned long ha = 5381;
299299
char const *ptr = *data;
300300

301-
if (flags & XDF_WHITESPACE_FLAGS)
302-
return xdl_hash_record_with_whitespace(data, top, flags);
303-
304301
for (; ptr < top && *ptr != '\n'; ptr++) {
305302
ha += (ha << 5);
306303
ha ^= (unsigned long) *ptr;

xdiff/xutils.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ void *xdl_cha_alloc(chastore_t *cha);
3434
long xdl_guess_lines(mmfile_t *mf, long sample);
3535
int xdl_blankline(const char *line, long size, long flags);
3636
int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags);
37-
unsigned long xdl_hash_record(char const **data, char const *top, long flags);
37+
unsigned long xdl_hash_record_verbatim(char const **data, char const *top);
38+
unsigned long xdl_hash_record_with_whitespace(char const **data, char const *top, long flags);
39+
static inline unsigned long xdl_hash_record(char const **data, char const *top, long flags)
40+
{
41+
if (flags & XDF_WHITESPACE_FLAGS)
42+
return xdl_hash_record_with_whitespace(data, top, flags);
43+
else
44+
return xdl_hash_record_verbatim(data, top);
45+
}
3846
unsigned int xdl_hashbits(unsigned int size);
3947
int xdl_num_out(char *out, long val);
4048
int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,

0 commit comments

Comments
 (0)