summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2015-03-16 21:35:02 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2015-03-16 21:35:02 (GMT)
commitda9402c6f563ded59a41c772afb9307962833d60 (patch)
treeb59bbc4fa37cb19fe8be44888da385e6af8c17ef /lib
parent859fe3bb1d5ccadc10bd6b03b31e762397cf346e (diff)
downloadlz4-da9402c6f563ded59a41c772afb9307962833d60.zip
lz4-da9402c6f563ded59a41c772afb9307962833d60.tar.gz
lz4-da9402c6f563ded59a41c772afb9307962833d60.tar.bz2
minor lz4frame refactoring
Diffstat (limited to 'lib')
-rw-r--r--lib/lz4.h14
-rw-r--r--lib/lz4frame.c49
2 files changed, 26 insertions, 37 deletions
diff --git a/lib/lz4.h b/lib/lz4.h
index f04344b..db55b11 100644
--- a/lib/lz4.h
+++ b/lib/lz4.h
@@ -45,7 +45,7 @@ extern "C" {
*/
/**************************************
- Version
+* Version
**************************************/
#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
#define LZ4_VERSION_MINOR 5 /* for new (non-breaking) interface capabilities */
@@ -54,7 +54,7 @@ extern "C" {
int LZ4_versionNumber (void);
/**************************************
- Tuning parameter
+* Tuning parameter
**************************************/
/*
* LZ4_MEMORY_USAGE :
@@ -67,7 +67,7 @@ int LZ4_versionNumber (void);
/**************************************
- Simple Functions
+* Simple Functions
**************************************/
int LZ4_compress (const char* source, char* dest, int sourceSize);
@@ -96,7 +96,7 @@ LZ4_decompress_safe() :
/**************************************
- Advanced Functions
+* Advanced Functions
**************************************/
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
#define LZ4_COMPRESSBOUND(isize) ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
@@ -170,7 +170,7 @@ int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedS
/***********************************************
- Streaming Compression Functions
+* Streaming Compression Functions
***********************************************/
#define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4)
@@ -235,7 +235,7 @@ int LZ4_saveDict (LZ4_stream_t* LZ4_streamPtr, char* safeBuffer, int dictSize);
/************************************************
- Streaming Decompression Functions
+* Streaming Decompression Functions
************************************************/
#define LZ4_STREAMDECODESIZE_U64 4
@@ -286,7 +286,7 @@ int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalS
/**************************************
- Obsolete Functions
+* Obsolete Functions
**************************************/
/*
Obsolete decompression functions
diff --git a/lib/lz4frame.c b/lib/lz4frame.c
index d08cf94..ed47c0a 100644
--- a/lib/lz4frame.c
+++ b/lib/lz4frame.c
@@ -208,6 +208,21 @@ static BYTE LZ4F_headerChecksum (const BYTE* header, size_t length)
/**************************************
* Simple compression functions
**************************************/
+static blockSizeID_t LZ4F_optimalBSID(const blockSizeID_t requestedBSID, const size_t srcSize)
+{
+ blockSizeID_t proposedBSID = max64KB;
+ size_t maxBlockSize = 64 KB;
+ while (requestedBSID > proposedBSID)
+ {
+ if (srcSize <= maxBlockSize)
+ return proposedBSID;
+ proposedBSID = (blockSizeID_t)((int)proposedBSID + 1);
+ maxBlockSize <<= 2;
+ }
+ return requestedBSID;
+}
+
+
size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
{
LZ4F_preferences_t prefs;
@@ -217,20 +232,7 @@ size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* prefere
if (preferencesPtr!=NULL) prefs = *preferencesPtr;
else memset(&prefs, 0, sizeof(prefs));
- {
- blockSizeID_t proposedBSID = max64KB;
- size_t maxBlockSize = 64 KB;
- while (prefs.frameInfo.blockSizeID > proposedBSID)
- {
- if (srcSize <= maxBlockSize)
- {
- prefs.frameInfo.blockSizeID = proposedBSID;
- break;
- }
- proposedBSID = (blockSizeID_t)( ((int)proposedBSID) + 1);
- maxBlockSize <<= 2;
- }
- }
+ prefs.frameInfo.blockSizeID = LZ4F_optimalBSID(prefs.frameInfo.blockSizeID, srcSize);
prefs.autoFlush = 1;
headerSize = 7; /* basic header size (no option) including magic number */
@@ -241,11 +243,11 @@ size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t* prefere
/* LZ4F_compressFrame()
-* Compress an entire srcBuffer into a valid LZ4 frame, as defined by specification v1.4.1, in a single step.
+* Compress an entire srcBuffer into a valid LZ4 frame, as defined by specification v1.5.0, in a single step.
* The most important rule is that dstBuffer MUST be large enough (dstMaxSize) to ensure compression completion even in worst case.
* You can get the minimum value of dstMaxSize by using LZ4F_compressFrameBound()
* If this condition is not respected, LZ4F_compressFrame() will fail (result is an errorCode)
-* The LZ4F_preferences_t structure is optional : you can provide NULL as argument. All preferences will be set to default.
+* The LZ4F_preferences_t structure is optional : you can provide NULL as argument. All preferences will then be set to default.
* The result of the function is the number of bytes written into dstBuffer.
* The function outputs an error code if it fails (can be tested using LZ4F_isError())
*/
@@ -268,20 +270,7 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf
if (preferencesPtr!=NULL) prefs = *preferencesPtr;
else memset(&prefs, 0, sizeof(prefs));
- {
- blockSizeID_t proposedBSID = max64KB;
- size_t maxBlockSize = 64 KB;
- while (prefs.frameInfo.blockSizeID > proposedBSID)
- {
- if (srcSize <= maxBlockSize)
- {
- prefs.frameInfo.blockSizeID = proposedBSID;
- break;
- }
- proposedBSID = (blockSizeID_t)((int)proposedBSID + 1);
- maxBlockSize <<= 2;
- }
- }
+ prefs.frameInfo.blockSizeID = LZ4F_optimalBSID(prefs.frameInfo.blockSizeID, srcSize);
prefs.autoFlush = 1;
if (srcSize <= LZ4F_getBlockSize(prefs.frameInfo.blockSizeID))
prefs.frameInfo.blockMode = blockIndependent; /* no need for linked blocks */