diff options
author | W. Felix Handte <w@felixhandte.com> | 2018-04-20 18:52:13 (GMT) |
---|---|---|
committer | W. Felix Handte <w@felixhandte.com> | 2018-04-20 18:59:34 (GMT) |
commit | d7347f9eeaffe5351886b6174f9974bd541b9b7d (patch) | |
tree | 32aeb9a6efdd431fdaa9a6f4c9967aaf1be9b7d6 /lib | |
parent | ca833f928f64d0b88fbfd2a8a8bc11b8333e487d (diff) | |
download | lz4-d7347f9eeaffe5351886b6174f9974bd541b9b7d.zip lz4-d7347f9eeaffe5351886b6174f9974bd541b9b7d.tar.gz lz4-d7347f9eeaffe5351886b6174f9974bd541b9b7d.tar.bz2 |
Add API for Attaching Dictionaries
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lz4frame.c | 3 | ||||
-rw-r--r-- | lib/lz4hc.c | 3 | ||||
-rw-r--r-- | lib/lz4hc.h | 27 |
3 files changed, 31 insertions, 2 deletions
diff --git a/lib/lz4frame.c b/lib/lz4frame.c index a43f595..d4d9397 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -549,9 +549,8 @@ static void LZ4F_applyCDict(void* ctx, LZ4_resetStream_fast((LZ4_stream_t *)ctx); LZ4_attach_dictionary((LZ4_stream_t *)ctx, cdict ? cdict->fastCtx : NULL); } else { - LZ4HC_CCtx_internal *internal_ctx = &((LZ4_streamHC_t *)ctx)->internal_donotuse; LZ4_resetStreamHC_fast((LZ4_streamHC_t*)ctx, level); - internal_ctx->dictCtx = cdict ? &(cdict->HCCtx->internal_donotuse) : NULL; + LZ4_attach_HC_dictionary((LZ4_streamHC_t *)ctx, cdict ? cdict->HCCtx : NULL); } } diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 124da86..690015f 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -887,6 +887,9 @@ int LZ4_loadDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, const char* dictionary, int return dictSize; } +void LZ4_attach_HC_dictionary(LZ4_streamHC_t *working_stream, const LZ4_streamHC_t *dictionary_stream) { + working_stream->internal_donotuse.dictCtx = dictionary_stream != NULL ? &(dictionary_stream->internal_donotuse) : NULL; +} /* compression */ diff --git a/lib/lz4hc.h b/lib/lz4hc.h index cfc5d9e..fb8397e 100644 --- a/lib/lz4hc.h +++ b/lib/lz4hc.h @@ -279,5 +279,32 @@ void LZ4_resetStreamHC_fast(LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLeve int LZ4_compress_HC_extStateHC_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int compressionLevel); +/*! LZ4_attach_HC_dictionary() : + * This is an experimental API that allows for the efficient use of a + * static dictionary many times. + * + * Rather than re-loading the dictionary buffer into a working context before + * each compression, or copying a pre-loaded dictionary's LZ4_streamHC_t into a + * working LZ4_streamHC_t, this function introduces a no-copy setup mechanism, + * in which the working stream references the dictionary stream in-place. + * + * Several assumptions are made about the state of the dictionary stream. + * Currently, only streams which have been prepared by LZ4_loadDictHC() should + * be expected to work. + * + * Alternatively, the provided dictionary stream pointer may be NULL, in which + * case any existing dictionary stream is unset. + * + * A dictionary should only be attached to a stream without any history (i.e., + * a stream that has just been reset). + * + * The dictionary will remain attached to the working stream only for the + * current stream session. Calls to LZ4_resetStreamHC(_fast) will remove the + * dictionary context association from the working stream. The dictionary + * stream (and source buffer) must remain in-place / accessible / unchanged + * through the lifetime of the stream session. + */ +LZ4LIB_API void LZ4_attach_HC_dictionary(LZ4_streamHC_t *working_stream, const LZ4_streamHC_t *dictionary_stream); + #endif /* LZ4_HC_SLO_098092834 */ #endif /* LZ4_HC_STATIC_LINKING_ONLY */ |