Skip to content

Commit

Permalink
remove some do while loops
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Dec 31, 2024
1 parent 2816d03 commit 2802700
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/bmffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ class BrotliDecoderWrapper {
void BmffImage::brotliUncompress(const byte* compressedBuf, size_t compressedBufSize, DataBuf& arr) {
BrotliDecoderWrapper decoder;
size_t uncompressedLen = compressedBufSize * 2; // just a starting point
BrotliDecoderResult result;
BrotliDecoderResult result = BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT;
int dos = 0;
size_t available_in = compressedBufSize;
const byte* next_in = compressedBuf;
size_t available_out;
byte* next_out;
size_t total_out = 0;

do {
while (result != BROTLI_DECODER_RESULT_SUCCESS) {
arr.alloc(uncompressedLen);
available_out = uncompressedLen - total_out;
next_out = arr.data() + total_out;
Expand All @@ -234,7 +234,7 @@ void BmffImage::brotliUncompress(const byte* compressedBuf, size_t compressedBuf
// something bad happened
throw Error(ErrorCode::kerErrorMessage, BrotliDecoderErrorString(BrotliDecoderGetErrorCode(decoder.get())));
}
} while (result != BROTLI_DECODER_RESULT_SUCCESS);
};

if (result != BROTLI_DECODER_RESULT_SUCCESS) {
throw Error(ErrorCode::kerFailedToReadImageData);
Expand Down
4 changes: 2 additions & 2 deletions src/minoltamn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,15 +1674,15 @@ static std::vector<std::string> split(const std::string& str, const std::string&
std::vector<std::string> tokens;
size_t prev = 0;
size_t pos = 0;
do {
while (pos < str.length() && prev < str.length()) {
pos = str.find(delim, prev);
if (pos == std::string::npos)
pos = str.length();
std::string token = str.substr(prev, pos - prev);
if (!token.empty())
tokens.push_back(std::move(token));
prev = pos + delim.length();
} while (pos < str.length() && prev < str.length());
};
return tokens;
}

Expand Down
12 changes: 6 additions & 6 deletions src/pngchunk_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ std::string PngChunk::makeMetadataChunk(const std::string& metadata, MetadataId

void PngChunk::zlibUncompress(const byte* compressedText, unsigned int compressedTextSize, DataBuf& arr) {
uLongf uncompressedLen = compressedTextSize * 2; // just a starting point
int zlibResult;
int zlibResult = Z_BUF_ERROR;
int dos = 0;

do {
while (zlibResult == Z_BUF_ERROR) {
arr.alloc(uncompressedLen);
zlibResult = uncompress(arr.data(), &uncompressedLen, compressedText, compressedTextSize);
if (zlibResult == Z_OK) {
Expand All @@ -355,7 +355,7 @@ void PngChunk::zlibUncompress(const byte* compressedText, unsigned int compresse
// something bad happened
throw Error(ErrorCode::kerFailedToReadImageData);
}
} while (zlibResult == Z_BUF_ERROR);
};

if (zlibResult != Z_OK) {
throw Error(ErrorCode::kerFailedToReadImageData);
Expand All @@ -364,10 +364,10 @@ void PngChunk::zlibUncompress(const byte* compressedText, unsigned int compresse

std::string PngChunk::zlibCompress(const std::string& text) {
auto compressedLen = static_cast<uLongf>(text.size() * 2); // just a starting point
int zlibResult;
int zlibResult = Z_BUF_ERROR;

DataBuf arr;
do {
while (zlibResult == Z_BUF_ERROR) {
arr.resize(compressedLen);
zlibResult = compress2(arr.data(), &compressedLen, reinterpret_cast<const Bytef*>(text.data()),
static_cast<uLong>(text.size()), Z_BEST_COMPRESSION);
Expand All @@ -390,7 +390,7 @@ std::string PngChunk::zlibCompress(const std::string& text) {
// Something bad happened
throw Error(ErrorCode::kerFailedToReadImageData);
}
} while (zlibResult == Z_BUF_ERROR);
};

return {arr.c_str(), arr.size()};

Expand Down

0 comments on commit 2802700

Please sign in to comment.