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



##########
File path: src/tscore/fastlz.cc
##########
@@ -0,0 +1,635 @@
+/*
+  FastLZ - Byte-aligned LZ77 compression library
+  Copyright (C) 2005-2020 Ariya Hidayat <[email protected]>
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+#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(__clang__) || (defined(__GNUC__) && (__GNUC__ > 2))
+#define FASTLZ_LIKELY(c) (__builtin_expect(!!(c), 1))
+#define FASTLZ_UNLIKELY(c) (__builtin_expect(!!(c), 0))
+#else
+#define FASTLZ_LIKELY(c) (c)
+#define FASTLZ_UNLIKELY(c) (c)
+#endif
+
+/*
+ * Specialize custom 64-bit implementation for speed improvements.
+ */
+#if defined(__x86_64__) || defined(_M_X64)
+#define FLZ_ARCH64
+#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
+
+#if defined(FASTLZ_USE_MEMMOVE) && (FASTLZ_USE_MEMMOVE == 0)
+
+static void
+fastlz_memmove(uint8_t *dest, const uint8_t *src, uint32_t count)
+{
+  do {
+    *dest++ = *src++;
+  } while (--count);
+}
+
+static void
+fastlz_memcpy(uint8_t *dest, const uint8_t *src, uint32_t count)
+{
+  return fastlz_memmove(dest, src, count);
+}
+
+#else
+
+#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:
       `[[fallthrough]]` added. Moved to lib/fastlz and renamed to .cc




-- 
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