Skip to content

Commit 7726c15

Browse files
Flatten control flow in fillBuffer to improve readability and intent
1 parent 1bb4d53 commit 7726c15

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/OpenStreetMap-esp32.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -292,29 +292,30 @@ bool OpenStreetMap::fillBuffer(WiFiClient *stream, MemoryBuffer &buffer, size_t
292292
while (readSize < contentSize)
293293
{
294294
const size_t availableData = stream->available();
295-
if (availableData)
296-
{
297-
const size_t remaining = contentSize - readSize;
298-
const size_t toRead = std::min(availableData, remaining);
299-
const int bytesRead = stream->readBytes(buffer.get() + readSize, toRead);
300-
301-
if (bytesRead > 0)
302-
{
303-
readSize += bytesRead;
304-
lastReadTime = millis();
305-
}
306-
else
307-
vTaskDelay(pdMS_TO_TICKS(1));
308-
}
309-
else
295+
if (!availableData)
310296
{
311297
if (millis() - lastReadTime >= OSM_TILE_TIMEOUT_MS)
312298
{
313-
result = "Timeout: No data received within " + String(OSM_TILE_TIMEOUT_MS) + " ms";
299+
result = "Timeout: " + String(OSM_TILE_TIMEOUT_MS) + " ms";
314300
return false;
315301
}
316302
vTaskDelay(pdMS_TO_TICKS(1));
303+
continue;
317304
}
305+
306+
const size_t remaining = contentSize - readSize;
307+
const size_t toRead = std::min(availableData, remaining);
308+
if (toRead == 0)
309+
continue;
310+
311+
const int bytesRead = stream->readBytes(buffer.get() + readSize, toRead);
312+
if (bytesRead > 0)
313+
{
314+
readSize += bytesRead;
315+
lastReadTime = millis();
316+
}
317+
else
318+
vTaskDelay(pdMS_TO_TICKS(1));
318319
}
319320
return true;
320321
}

0 commit comments

Comments
 (0)