Skip to content

Commit

Permalink
istream/Replace: refactor local variables in _GetAvailable()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Aug 12, 2023
1 parent a59957c commit ec91d99
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/istream/ReplaceIstream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -322,31 +322,32 @@ ReplaceIstream::_GetAvailable(bool partial) noexcept

/* get available bytes from input */

off_t length = 0;
off_t input_avalable = 0;
if (HasInput() && finished) {
length = input.GetAvailable(partial);
if (length == (off_t)-1) {
input_avalable = input.GetAvailable(partial);
if (input_avalable == (off_t)-1) {
if (!partial)
return (off_t)-1;
length = 0;
input_avalable = 0;
}
}

/* add available bytes from substitutions (and the source buffers
before the substitutions) */

off_t available = input_avalable;
off_t position2 = position;

for (auto subst = first_substitution;
subst != nullptr; subst = subst->next) {
assert(position2 <= subst->start);

length += subst->start - position2;
available += subst->start - position2;

if (subst->IsDefined()) {
const off_t l = subst->GetAvailable(partial);
if (l != (off_t)-1)
length += l;
available += l;
else if (!partial)
return (off_t)-1;
}
Expand All @@ -357,9 +358,9 @@ ReplaceIstream::_GetAvailable(bool partial) noexcept
/* add available bytes from tail (if known yet) */

if (finished)
length += source_length - position2;
available += source_length - position2;

return length;
return available;
}

void
Expand Down

0 comments on commit ec91d99

Please sign in to comment.