A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
This commit is contained in:
@ -26,25 +26,25 @@
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "zlib.h"
|
||||
#include "os/copymem.h"
|
||||
#include "compression.h"
|
||||
#include "os/copymem.h"
|
||||
#include "zlib.h"
|
||||
|
||||
#include "fastlz.h"
|
||||
#include "zip_io.h"
|
||||
|
||||
int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,Mode p_mode) {
|
||||
int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode) {
|
||||
|
||||
switch(p_mode) {
|
||||
switch (p_mode) {
|
||||
case MODE_FASTLZ: {
|
||||
|
||||
if (p_src_size<16) {
|
||||
if (p_src_size < 16) {
|
||||
uint8_t src[16];
|
||||
zeromem(&src[p_src_size],16-p_src_size);
|
||||
copymem(src,p_src,p_src_size);
|
||||
return fastlz_compress(src,16,p_dst);
|
||||
zeromem(&src[p_src_size], 16 - p_src_size);
|
||||
copymem(src, p_src, p_src_size);
|
||||
return fastlz_compress(src, 16, p_dst);
|
||||
} else {
|
||||
return fastlz_compress(p_src,p_src_size,p_dst);
|
||||
return fastlz_compress(p_src, p_src_size, p_dst);
|
||||
}
|
||||
|
||||
} break;
|
||||
@ -54,20 +54,20 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,M
|
||||
strm.zalloc = zipio_alloc;
|
||||
strm.zfree = zipio_free;
|
||||
strm.opaque = Z_NULL;
|
||||
int err = deflateInit(&strm,Z_DEFAULT_COMPRESSION);
|
||||
if (err!=Z_OK)
|
||||
return -1;
|
||||
int err = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
|
||||
if (err != Z_OK)
|
||||
return -1;
|
||||
|
||||
strm.avail_in=p_src_size;
|
||||
int aout = deflateBound(&strm,p_src_size);
|
||||
strm.avail_in = p_src_size;
|
||||
int aout = deflateBound(&strm, p_src_size);
|
||||
/*if (aout>p_src_size) {
|
||||
deflateEnd(&strm);
|
||||
return -1;
|
||||
}*/
|
||||
strm.avail_out=aout;
|
||||
strm.next_in=(Bytef*)p_src;
|
||||
strm.next_out=p_dst;
|
||||
deflate(&strm,Z_FINISH);
|
||||
strm.avail_out = aout;
|
||||
strm.next_in = (Bytef *)p_src;
|
||||
strm.next_out = p_dst;
|
||||
deflate(&strm, Z_FINISH);
|
||||
aout = aout - strm.avail_out;
|
||||
deflateEnd(&strm);
|
||||
return aout;
|
||||
@ -78,15 +78,14 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,M
|
||||
ERR_FAIL_V(-1);
|
||||
}
|
||||
|
||||
int Compression::get_max_compressed_buffer_size(int p_src_size,Mode p_mode){
|
||||
int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
|
||||
|
||||
switch(p_mode) {
|
||||
switch (p_mode) {
|
||||
case MODE_FASTLZ: {
|
||||
|
||||
|
||||
int ss = p_src_size+p_src_size*6/100;
|
||||
if (ss<66)
|
||||
ss=66;
|
||||
int ss = p_src_size + p_src_size * 6 / 100;
|
||||
if (ss < 66)
|
||||
ss = 66;
|
||||
return ss;
|
||||
|
||||
} break;
|
||||
@ -96,34 +95,31 @@ int Compression::get_max_compressed_buffer_size(int p_src_size,Mode p_mode){
|
||||
strm.zalloc = zipio_alloc;
|
||||
strm.zfree = zipio_free;
|
||||
strm.opaque = Z_NULL;
|
||||
int err = deflateInit(&strm,Z_DEFAULT_COMPRESSION);
|
||||
if (err!=Z_OK)
|
||||
return -1;
|
||||
int aout = deflateBound(&strm,p_src_size);
|
||||
int err = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
|
||||
if (err != Z_OK)
|
||||
return -1;
|
||||
int aout = deflateBound(&strm, p_src_size);
|
||||
deflateEnd(&strm);
|
||||
return aout;
|
||||
} break;
|
||||
}
|
||||
|
||||
ERR_FAIL_V(-1);
|
||||
|
||||
}
|
||||
|
||||
int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode) {
|
||||
|
||||
|
||||
int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size,Mode p_mode){
|
||||
|
||||
switch(p_mode) {
|
||||
switch (p_mode) {
|
||||
case MODE_FASTLZ: {
|
||||
|
||||
int ret_size=0;
|
||||
int ret_size = 0;
|
||||
|
||||
if (p_dst_max_size<16) {
|
||||
if (p_dst_max_size < 16) {
|
||||
uint8_t dst[16];
|
||||
ret_size = fastlz_decompress(p_src,p_src_size,dst,16);
|
||||
copymem(p_dst,dst,p_dst_max_size);
|
||||
ret_size = fastlz_decompress(p_src, p_src_size, dst, 16);
|
||||
copymem(p_dst, dst, p_dst_max_size);
|
||||
} else {
|
||||
ret_size = fastlz_decompress(p_src,p_src_size,p_dst,p_dst_max_size);
|
||||
ret_size = fastlz_decompress(p_src, p_src_size, p_dst, p_dst_max_size);
|
||||
}
|
||||
return ret_size;
|
||||
} break;
|
||||
@ -133,20 +129,20 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p
|
||||
strm.zalloc = zipio_alloc;
|
||||
strm.zfree = zipio_free;
|
||||
strm.opaque = Z_NULL;
|
||||
strm.avail_in= 0;
|
||||
strm.next_in=Z_NULL;
|
||||
strm.avail_in = 0;
|
||||
strm.next_in = Z_NULL;
|
||||
int err = inflateInit(&strm);
|
||||
ERR_FAIL_COND_V(err!=Z_OK,-1);
|
||||
ERR_FAIL_COND_V(err != Z_OK, -1);
|
||||
|
||||
strm.avail_in=p_src_size;
|
||||
strm.avail_out=p_dst_max_size;
|
||||
strm.next_in=(Bytef*)p_src;
|
||||
strm.next_out=p_dst;
|
||||
strm.avail_in = p_src_size;
|
||||
strm.avail_out = p_dst_max_size;
|
||||
strm.next_in = (Bytef *)p_src;
|
||||
strm.next_out = p_dst;
|
||||
|
||||
err = inflate(&strm,Z_FINISH);
|
||||
err = inflate(&strm, Z_FINISH);
|
||||
int total = strm.total_out;
|
||||
inflateEnd(&strm);
|
||||
ERR_FAIL_COND_V(err!=Z_STREAM_END,-1);
|
||||
ERR_FAIL_COND_V(err != Z_STREAM_END, -1);
|
||||
return total;
|
||||
} break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user