From 4c91b8ea5950834693130343899e0fa379fd3be1 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Sun, 26 Dec 2010 10:01:42 -0600 Subject: Simple movement of return calculation in lcs_upper_bound This increased performance of the non-DO_SECOND_SUM code a _lot_ for something so small. --- lcs.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lcs.c') diff --git a/lcs.c b/lcs.c index 2346f12..d296ea7 100644 --- a/lcs.c +++ b/lcs.c @@ -158,7 +158,7 @@ int lcs_32_rough(unsigned char *str1, unsigned char *str2) { #endif #ifdef USE_PRE_LCS -#define DO_SECOND_SUM +//efine DO_SECOND_SUM #ifdef DO_SECOND_SUM #include "arpa/inet.h" @@ -169,6 +169,7 @@ int lcs_upper_bound(const uint32_t * const str1_int, const uint32_t * const str2 const unsigned char * const str1 = (const unsigned char * const)str1_int; const unsigned char * const str2 = (const unsigned char * const)str2_int; int first_sum; + int ret; #ifdef DO_SECOND_SUM uint32_t bo_str2_int[4]; uint32_t shifted_str2_int[4]; @@ -207,6 +208,12 @@ int lcs_upper_bound(const uint32_t * const str1_int, const uint32_t * const str2 + contains[str2_r[9]] + contains[str2_r[10]] + contains[str2_r[11]] + contains[str2_r[12]] + contains[str2_r[13]] + contains[str2_r[14]] + contains[str2_r[15]]; + + // can be off up to one nibble (e.g., "1110" and "2111") + ret = MAX(first_sum, second_sum) * 2 + 1; +#else + // can be off up to two nibbles (e.g., "0110" and "1122") + ret = first_sum * 2 + 2; #endif contains[str1[0]] = contains[str1[1]] = contains[str1[2]] @@ -216,13 +223,7 @@ int lcs_upper_bound(const uint32_t * const str1_int, const uint32_t * const str2 = contains[str1[12]] = contains[str1[13]] = contains[str1[14]] = contains[str1[15]] = 0; -#ifdef DO_SECOND_SUM - // can be off up to one nibble (e.g., "1110" and "2111") - return MAX(first_sum, second_sum) * 2 + 1; -#else - // can be off up to two nibbles (e.g., "0110" and "1122") - return first_sum * 2 + 2; -#endif + return ret; } #endif -- cgit v1.2.3-70-g09d2