Skip to content

Commit a33c31c

Browse files
committed
Code tweaks
1 parent c598901 commit a33c31c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/Memory.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ limitations under the License.
2020
#include <cstring>
2121
#include "types.hpp"
2222

23+
#if defined(__GNUC__) || defined(__clang__)
24+
#define LIKELY(x) __builtin_expect(!!(x), 1)
25+
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
26+
#else
27+
// For MSVC and other compilers, the macro does nothing.
28+
#define LIKELY(x) (x)
29+
#define UNLIKELY(x) (x)
30+
#endif
31+
32+
2333
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || defined(BSD)
2434
#include <machine/endian.h>
2535
#elif defined(__APPLE__)

src/transform/DivSufSort.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using namespace kanzi;
2222

2323

2424
const int DivSufSort::SS_INSERTIONSORT_THRESHOLD = 16;
25-
const int DivSufSort::SS_BLOCKSIZE = 4096;
25+
const int DivSufSort::SS_BLOCKSIZE = 8192;
2626
const int DivSufSort::SS_MISORT_STACKSIZE = 16;
2727
const int DivSufSort::SS_SMERGE_STACKSIZE = 32;
2828
const int DivSufSort::TR_STACKSIZE = 64;
@@ -486,9 +486,7 @@ void DivSufSort::ssSort(const int pa, int first, int last, int buf, int bufSize,
486486
limit = ssIsqrt(last - first);
487487

488488
if (bufSize < limit) {
489-
if (limit > SS_BLOCKSIZE)
490-
limit = SS_BLOCKSIZE;
491-
489+
limit = limit > SS_BLOCKSIZE ? SS_BLOCKSIZE : limit;
492490
middle = last - limit;
493491
buf = middle;
494492
bufSize = limit;
@@ -554,7 +552,6 @@ void DivSufSort::ssSort(const int pa, int first, int last, int buf, int bufSize,
554552

555553
int DivSufSort::ssCompare(int pa, int pb, int p2, const int depth) const
556554
{
557-
prefetchRead(&_sa[p2]);
558555
int u1 = depth + pa;
559556
int u2 = depth + _sa[p2];
560557
const int u1n = pb + 2;
@@ -579,8 +576,6 @@ int DivSufSort::ssCompare(int pa, int pb, int p2, const int depth) const
579576

580577
int DivSufSort::ssCompare(const int sa1[], const int sa2[], const int depth) const
581578
{
582-
prefetchRead(&sa1[0]);
583-
prefetchRead(&sa2[2]);
584579
int u1 = depth + sa1[0];
585580
int u2 = depth + sa2[0];
586581
const int u1n = sa1[1] + 2;
@@ -1103,9 +1098,7 @@ void DivSufSort::ssInsertionSort(const int pa, int first, int last, int depth)
11031098
break;
11041099
}
11051100

1106-
if (r == 0)
1107-
_sa[j] = ~_sa[j];
1108-
1101+
_sa[j] = r == 0 ? ~_sa[j] : _sa[j];
11091102
_sa[j - 1] = t - pa;
11101103
}
11111104
}

0 commit comments

Comments
 (0)