]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
rewrote ZSTD_cwksp_initialAllocStart() to be easier to read
authorYann Collet <cyan@fb.com>
Tue, 22 Oct 2024 23:22:17 +0000 (16:22 -0700)
committerYann Collet <cyan@fb.com>
Wed, 23 Oct 2024 18:50:57 +0000 (11:50 -0700)
following a discussion with @felixhandte

lib/compress/zstd_cwksp.h

index 77715e22e533a69dd415429c0dbf5506f660c488..aa4c3e49e08f49ef796c62cda88ea7c2b8d45c69 100644 (file)
@@ -17,6 +17,7 @@
 #include "../common/allocations.h"  /* ZSTD_customMalloc, ZSTD_customFree */
 #include "../common/zstd_internal.h"
 #include "../common/portability_macros.h"
+#include "../common/compiler.h" /* ZS2_isPower2 */
 
 #if defined (__cplusplus)
 extern "C" {
@@ -275,8 +276,12 @@ MEM_STATIC size_t ZSTD_cwksp_bytes_to_align_ptr(void* ptr, const size_t alignByt
  * Returns the initial value for allocStart which is used to determine the position from
  * which we can allocate from the end of the workspace.
  */
-MEM_STATIC void*  ZSTD_cwksp_initialAllocStart(ZSTD_cwksp* ws) {
-    return (void*)((size_t)ws->workspaceEnd & (size_t)~(ZSTD_CWKSP_ALIGNMENT_BYTES-1));
+MEM_STATIC void*  ZSTD_cwksp_initialAllocStart(ZSTD_cwksp* ws)
+{
+    char* endPtr = (char*)ws->workspaceEnd;
+    assert(ZSTD_isPower2(ZSTD_CWKSP_ALIGNMENT_BYTES));
+    endPtr = endPtr - ((size_t)endPtr % ZSTD_CWKSP_ALIGNMENT_BYTES);
+    return (void*)endPtr;
 }
 
 /**