]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Clean Up TODOs and Comments
authorW. Felix Handte <w@felixhandte.com>
Wed, 14 Aug 2019 21:11:16 +0000 (17:11 -0400)
committerW. Felix Handte <w@felixhandte.com>
Mon, 9 Sep 2019 17:34:08 +0000 (13:34 -0400)
lib/compress/zstd_compress.c
lib/compress/zstd_compress_internal.h

index 262efead5ecd1a9e840f6bf404f52097ad37bc82..7002e0d439716ae1189dd9b42f2ec5c2677e7c6a 100644 (file)
@@ -51,11 +51,16 @@ size_t ZSTD_compressBound(size_t srcSize) {
 /**
  * Align must be a power of 2.
  */
-static size_t ZSTD_workspace_align(size_t size, size_t align) {
-    return size + align - 1 - ((size - 1) & (align - 1));
+static size_t ZSTD_workspace_align(size_t size, size_t const align) {
+    size_t const mask = align - 1;
+    assert((align & mask) == 0);
+    return (size + mask) & ~mask;
 }
 
-static void* ZSTD_workspace_reserve(ZSTD_CCtx_workspace* ws, size_t bytes, ZSTD_workspace_alloc_phase_e phase) {
+/**
+ * Internal function, use wrappers instead.
+ */
+static void* ZSTD_workspace_reserve_internal(ZSTD_CCtx_workspace* ws, size_t bytes, ZSTD_workspace_alloc_phase_e phase) {
     /* TODO(felixh): alignment */
     void* alloc = (BYTE *)ws->allocStart - bytes;
     void* bottom = ws->tableEnd;
@@ -88,6 +93,21 @@ static void* ZSTD_workspace_reserve(ZSTD_CCtx_workspace* ws, size_t bytes, ZSTD_
     return alloc;
 }
 
+/**
+ * Unaligned.
+ */
+static BYTE* ZSTD_workspace_reserve_buffer(ZSTD_CCtx_workspace* ws, size_t bytes) {
+    return (BYTE*)ZSTD_workspace_reserve_internal(ws, bytes, ZSTD_workspace_alloc_buffers);
+}
+
+/**
+ * Aligned on sizeof(unsigned).
+ */
+static void* ZSTD_workspace_reserve_aligned(ZSTD_CCtx_workspace* ws, size_t bytes) {
+    assert((bytes & (sizeof(U32)-1)) == 0); // TODO ???
+    return ZSTD_workspace_reserve_internal(ws, ZSTD_workspace_align(bytes, sizeof(U32)), ZSTD_workspace_alloc_aligned);
+}
+
 /**
  * Aligned on sizeof(unsigned). These buffers have the special property that
  * their values remain constrained, allowing us to re-use them without
@@ -126,7 +146,8 @@ static void* ZSTD_workspace_reserve_object(ZSTD_CCtx_workspace* ws, size_t bytes
     void* start = ws->objectEnd;
     void* end = (BYTE*)start + roundedBytes;
     DEBUGLOG(3, "wksp: reserving %zd bytes object (rounded to %zd), %zd bytes remaining", bytes, roundedBytes, (BYTE *)ws->workspaceEnd - (BYTE *)end);
-    assert((bytes & (sizeof(void*)-1)) == 0); // TODO ???
+    assert(((size_t)start & (sizeof(void*)-1)) == 0);
+    assert((bytes & (sizeof(void*)-1)) == 0);
     if (ws->phase != ZSTD_workspace_alloc_objects || end > ws->workspaceEnd) {
         DEBUGLOG(3, "wksp: object alloc failed!");
         ws->allocFailed = 1;
@@ -137,21 +158,6 @@ static void* ZSTD_workspace_reserve_object(ZSTD_CCtx_workspace* ws, size_t bytes
     return start;
 }
 
-/**
- * Aligned on sizeof(unsigned).
- */
-static void* ZSTD_workspace_reserve_aligned(ZSTD_CCtx_workspace* ws, size_t bytes) {
-    assert((bytes & (sizeof(U32)-1)) == 0); // TODO ???
-    return ZSTD_workspace_reserve(ws, ZSTD_workspace_align(bytes, sizeof(U32)), ZSTD_workspace_alloc_aligned);
-}
-
-/**
- * Unaligned.
- */
-static BYTE* ZSTD_workspace_reserve_buffer(ZSTD_CCtx_workspace* ws, size_t bytes) {
-    return (BYTE*)ZSTD_workspace_reserve(ws, bytes, ZSTD_workspace_alloc_buffers);
-}
-
 // TODO
 static int ZSTD_workspace_bump_oversized_duration(ZSTD_CCtx_workspace* ws) {
     (void)ws;
@@ -185,16 +191,11 @@ static void ZSTD_workspace_clear(ZSTD_CCtx_workspace* ws) {
     if (ws->phase > ZSTD_workspace_alloc_buffers) {
         ws->phase = ZSTD_workspace_alloc_buffers;
     }
-
-    // ws->table = NULL;
-    // ws->tableEnd = NULL;
-
-    // ws->bufferBegin = ws->workspaceEnd;
 }
 
 static void ZSTD_workspace_init(ZSTD_CCtx_workspace* ws, void* start, size_t size) {
     DEBUGLOG(3, "wksp: init'ing with %zd bytes", size);
-    assert(((size_t)start & (sizeof(void*)-1)) == 0);   /* ensure correct alignment */
+    assert(((size_t)start & (sizeof(void*)-1)) == 0); /* ensure correct alignment */
     ws->workspace = start;
     ws->workspaceEnd = (BYTE*)start + size;
     ws->objectEnd = ws->workspace;
@@ -1723,7 +1724,6 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
                 /* Statically sized space.
                  * entropyWorkspace never moves,
                  * though prev/next block swap places */
-                /* assert(((size_t)zc->workspace.workspace & 3) == 0); */   /* ensure correct alignment */ /* TODO(felixh): check elsewhere */
                 assert(ZSTD_workspace_check_available(&zc->workspace, 2 * sizeof(ZSTD_compressedBlockState_t)));
                 zc->blockState.prevCBlock = (ZSTD_compressedBlockState_t*) ZSTD_workspace_reserve_object(&zc->workspace, sizeof(ZSTD_compressedBlockState_t));
                 RETURN_ERROR_IF(zc->blockState.prevCBlock == NULL, memory_allocation, "couldn't allocate prevCBlock");
index 52d15544c26520501f3410a5cd43d41571e5a72e..fd3d030d2be499352e054f03441c07d7dd7059c8 100644 (file)
@@ -273,7 +273,7 @@ typedef enum {
  *   Examples:
  *   - Entropy Workspace
  *   - 2 x ZSTD_compressedBlockState_t
- *   - CDict dictionary contents sometimes??? // TODO
+ *   - CDict dictionary contents
  *
  * - Tables: these are any of several different datastructures (hash tables,
  *   chain tables, binary trees) that all respect a common format: they are
@@ -296,15 +296,17 @@ typedef enum {
  * 2. Buffers
  * 3. Aligned
  * 4. Tables
+ *
+ * Reusing Table Space:
+ *
+ * TODO(felixh): ...
  */
 typedef struct {
     void* workspace;
     void* workspaceEnd;
 
     void* objectEnd;
-
     void* tableEnd;
-
     void* allocStart;
 
     int allocFailed;