ywkaras commented on a change in pull request #8245:
URL: https://github.com/apache/trafficserver/pull/8245#discussion_r688848379



##########
File path: src/tscore/fastlz.c
##########
@@ -24,512 +21,615 @@
   THE SOFTWARE.
 */
 
-#if !defined(FASTLZ__COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR)
+#include "tscore/fastlz.h"
+
+#include <stdint.h>
 
 /*
  * Always check for bound when decompressing.
  * Generally it is best to leave it defined.
  */
 #define FASTLZ_SAFE
+#if defined(FASTLZ_USE_SAFE_DECOMPRESSOR) && (FASTLZ_USE_SAFE_DECOMPRESSOR == 
0)
+#undef FASTLZ_SAFE
+#endif
 
 /*
  * Give hints to the compiler for branch prediction optimization.
  */
-#if defined(__GNUC__) && (__GNUC__ > 2)
-#define FASTLZ_EXPECT_CONDITIONAL(c) (__builtin_expect((c), 1))
-#define FASTLZ_UNEXPECT_CONDITIONAL(c) (__builtin_expect((c), 0))
+#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 2))
+#define FASTLZ_LIKELY(c) (__builtin_expect(!!(c), 1))
+#define FASTLZ_UNLIKELY(c) (__builtin_expect(!!(c), 0))
 #else
-#define FASTLZ_EXPECT_CONDITIONAL(c) (c)
-#define FASTLZ_UNEXPECT_CONDITIONAL(c) (c)
+#define FASTLZ_LIKELY(c) (c)
+#define FASTLZ_UNLIKELY(c) (c)
 #endif
 
 /*
- * Use inlined functions for supported systems.
+ * Specialize custom 64-bit implementation for speed improvements.
  */
-#if defined(__GNUC__) || defined(__DMC__) || defined(__POCC__) || 
defined(__WATCOMC__) || defined(__SUNPRO_C)
-#define FASTLZ_INLINE inline
-#elif defined(__BORLANDC__) || defined(_MSC_VER) || defined(__LCC__)
-#define FASTLZ_INLINE __inline
-#else
-#define FASTLZ_INLINE
+#if defined(__x86_64__) || defined(_M_X64)
+#define FLZ_ARCH64
 #endif
 
-/*
- * Prevent accessing more than 8-bit at once, except on x86 architectures.
- */
-#if !defined(FASTLZ_STRICT_ALIGN)
-#define FASTLZ_STRICT_ALIGN
-#if defined(__i386__) || defined(__386) /* GNU C, Sun Studio */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(__i486__) || defined(__i586__) || defined(__i686__) /* GNU C */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(_M_IX86) /* Intel, MSVC */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(__386)
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(_X86_) /* MinGW */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(__I86__) /* Digital Mars */
-#undef FASTLZ_STRICT_ALIGN
-#endif
+#if defined(FASTLZ_SAFE)
+#define FASTLZ_BOUND_CHECK(cond) \
+  if (FASTLZ_UNLIKELY(!(cond)))  \
+    return 0;
+#else
+#define FASTLZ_BOUND_CHECK(cond) \
+  do {                           \
+  } while (0)
 #endif
 
-/*
- * FIXME: use preprocessor magic to set this on different platforms!
- */
-typedef unsigned char flzuint8;
-typedef unsigned short flzuint16;
-typedef unsigned int flzuint32;
+#if defined(FASTLZ_USE_MEMMOVE) && (FASTLZ_USE_MEMMOVE == 0)
 
-/* prototypes */
-int fastlz_compress(const void *input, int length, void *output);
-int fastlz_compress_level(int level, const void *input, int length, void 
*output);
-int fastlz_decompress(const void *input, int length, void *output, int maxout);
+static void
+fastlz_memmove(uint8_t *dest, const uint8_t *src, uint32_t count)
+{
+  do {
+    *dest++ = *src++;
+  } while (--count);
+}
 
-#define MAX_COPY 32
-#define MAX_LEN 264 /* 256 + 8 */
-#define MAX_DISTANCE 8192
+static void
+fastlz_memcpy(uint8_t *dest, const uint8_t *src, uint32_t count)
+{
+  return fastlz_memmove(dest, src, count);
+}
 
-#if !defined(FASTLZ_STRICT_ALIGN)
-#define FASTLZ_READU16(p) *((const flzuint16 *)(p))
 #else
-#define FASTLZ_READU16(p) ((p)[0] | (p)[1] << 8)
+
+#include <string.h>
+
+static void
+fastlz_memmove(uint8_t *dest, const uint8_t *src, uint32_t count)
+{
+  if ((count > 4) && (dest >= src + count)) {
+    memmove(dest, src, count);
+  } else {
+    switch (count) {
+    default:
+      do {
+        *dest++ = *src++;
+      } while (--count);
+      break;
+    case 3:
+      *dest++ = *src++;

Review comment:
       https://en.cppreference.com/w/cpp/language/attributes/fallthrough




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to