From bc9d1964fa2fd74d85ba8b33a9a3c8f7b427c59f Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Fri, 17 Jul 2026 13:48:56 +0200 Subject: [PATCH] feat: allow `strOut` argument to `fsst_compress` to be `NULL` The contents of `strOut` are strictly redundant as long as the lengths in `lenOut` are known. For long lists of strings, having to allocate a large buffer that is essentially going to be unused is something that should not be forced upon the user. The overhead for the additional check should be negligible even in the case where the pointer array is actually used. --- fsst.h | 2 +- libfsst.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fsst.h b/fsst.h index 71085d5..e31ec61 100644 --- a/fsst.h +++ b/fsst.h @@ -136,7 +136,7 @@ fsst_compress( size_t outsize, /* IN: byte-length of output buffer. */ unsigned char *output, /* OUT: memory buffer to put the compressed strings in (one after the other). */ size_t lenOut[], /* OUT: byte-lengths of the compressed strings. */ - unsigned char *strOut[] /* OUT: output string start pointers. Will all point into [output,output+size). */ + unsigned char *strOut[] /* OUT: output string start pointers. Will all point into [output,output+size). Can be NULL. */ ); /* Decompress a single string, inlined for speed. */ diff --git a/libfsst.cpp b/libfsst.cpp index e3ba787..b3eeb62 100644 --- a/libfsst.cpp +++ b/libfsst.cpp @@ -257,7 +257,7 @@ static inline size_t compressSIMD(SymbolTable &symbolTable, u8* symbolBase, size if (((len[curLine]-curOff)*2 + 7) > budget) break; // see below for the +7 else budget -= (len[curLine]-curOff)*2; - strOut[curLine] = (u8*) 0; + if (strOut) strOut[curLine] = (u8*) 0; lenOut[curLine] = 0; do { @@ -361,7 +361,7 @@ static inline size_t compressSIMD(SymbolTable &symbolTable, u8* symbolBase, size for(size_t i=0; i