Merge pull request #1724 from xiaoyifang/opt/while-once

fix: code smell ,remove while(1)
This commit is contained in:
xiaoyifang 2024-08-12 08:46:26 +08:00 committed by GitHub
commit 67a388455c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,10 +14,9 @@ QByteArray zlibDecompress( const char * bufptr, unsigned length )
memset( &zs, 0, sizeof( zs ) ); memset( &zs, 0, sizeof( zs ) );
zs.next_in = (Bytef *)bufptr; zs.next_in = (Bytef *)bufptr;
zs.avail_in = length; zs.avail_in = length;
while ( 1 ) { res = inflateInit( &zs );
res = inflateInit( &zs );
if ( res != Z_OK ) if ( res == Z_OK ) {
break;
while ( res != Z_STREAM_END ) { while ( res != Z_STREAM_END ) {
zs.next_out = (Bytef *)buf; zs.next_out = (Bytef *)buf;
zs.avail_out = CHUNK_SIZE; zs.avail_out = CHUNK_SIZE;
@ -26,8 +25,8 @@ QByteArray zlibDecompress( const char * bufptr, unsigned length )
if ( res != Z_OK && res != Z_STREAM_END ) if ( res != Z_OK && res != Z_STREAM_END )
break; break;
} }
break;
} }
inflateEnd( &zs ); inflateEnd( &zs );
if ( res != Z_STREAM_END ) if ( res != Z_STREAM_END )
str.clear(); str.clear();
@ -50,10 +49,8 @@ string decompressBzip2( const char * bufptr, unsigned length )
zs.next_in = (char *)bufptr; zs.next_in = (char *)bufptr;
zs.avail_in = length; zs.avail_in = length;
zs.total_in_lo32 = length; zs.total_in_lo32 = length;
while ( 1 ) { res = BZ2_bzDecompressInit( &zs, 0, 0 );
res = BZ2_bzDecompressInit( &zs, 0, 0 ); if ( res == BZ_OK ) {
if ( res != BZ_OK )
break;
while ( res != BZ_STREAM_END ) { while ( res != BZ_STREAM_END ) {
zs.next_out = buf; zs.next_out = buf;
zs.avail_out = CHUNK_SIZE; zs.avail_out = CHUNK_SIZE;
@ -63,7 +60,6 @@ string decompressBzip2( const char * bufptr, unsigned length )
if ( res != BZ_OK && res != BZ_STREAM_END ) if ( res != BZ_OK && res != BZ_STREAM_END )
break; break;
} }
break;
} }
BZ2_bzDecompressEnd( &zs ); BZ2_bzDecompressEnd( &zs );
if ( res != BZ_STREAM_END ) if ( res != BZ_STREAM_END )
@ -92,14 +88,13 @@ string decompressLzma2( const char * bufptr, unsigned length, bool raw_decoder )
filters[ 1 ].id = LZMA_VLI_UNKNOWN; filters[ 1 ].id = LZMA_VLI_UNKNOWN;
} }
while ( 1 ) {
if ( raw_decoder )
res = lzma_raw_decoder( &strm, filters );
else
res = lzma_stream_decoder( &strm, UINT64_MAX, 0 );
if ( res != LZMA_OK ) if ( raw_decoder )
break; res = lzma_raw_decoder( &strm, filters );
else
res = lzma_stream_decoder( &strm, UINT64_MAX, 0 );
if ( res == LZMA_OK ) {
while ( res != LZMA_STREAM_END ) { while ( res != LZMA_STREAM_END ) {
strm.next_out = reinterpret_cast< uint8_t * >( buf ); strm.next_out = reinterpret_cast< uint8_t * >( buf );
@ -112,8 +107,7 @@ string decompressLzma2( const char * bufptr, unsigned length, bool raw_decoder )
lzma_end( &strm ); lzma_end( &strm );
if ( res != LZMA_STREAM_END ) if ( res != LZMA_STREAM_END )
str.clear(); str.clear();
break;
} }
return str; return str;
} }