summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2015-12-26 22:23:43 +0100
committerJulian Andres Klode <jak@debian.org>2015-12-26 22:46:04 +0100
commit01152444ba96051fa0ca90b08dcbb8fec9d81745 (patch)
tree26c7240ea8f0e335e9060176abf065f17d283e43
parenta9024b1be2e26c3c6b1f67093ddbf7602636ec9f (diff)
Refactor InternalReadLine to not unroll Size == 0 case
There is not much point and this is more readable. Gbp-Dch: ignore
-rw-r--r--apt-pkg/contrib/fileutl.cc9
1 files changed, 4 insertions, 5 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index aa5831f58..99db66f03 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -970,13 +970,12 @@ public:
{
if (unlikely(Size == 0))
return nullptr;
+ // Read one byte less than buffer size to have space for trailing 0.
--Size;
- To[0] = '\0';
- if (unlikely(Size == 0))
- return To;
+
char * const InitialTo = To;
- do {
+ while (Size > 0) {
if (buffer.empty() == true)
{
buffer.reset();
@@ -1004,7 +1003,7 @@ public:
Size -= actualread;
if (newline != nullptr)
break;
- } while (Size > 0);
+ }
*To = '\0';
return InitialTo;
}