Skip to content

Commit

Permalink
Attempt to make CarbonProtocolReader::skip tail recursive
Browse files Browse the repository at this point in the history
Reviewed By: edenzik

Differential Revision: D17967570

fbshipit-source-id: fdc32e190a521349c7c8f4d6081902fa18eb0284
  • Loading branch information
Ted Reed authored and facebook-github-bot committed Nov 4, 2019
1 parent 2ac8b61 commit 97e033b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 9 additions & 9 deletions mcrouter/lib/carbon/CarbonProtocolReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ void CarbonProtocolReader::skip(const FieldType ft) {
}
case FieldType::Struct: {
readStructBegin();
while (true) {
const auto fieldType = readFieldHeader().first;
if (fieldType == FieldType::Stop) {
break;
}
skip(fieldType);
}
const auto next = readFieldHeader().first;
skip(next);
break;
}
case FieldType::Stop: {
readStructEnd();
break;
}
Expand All @@ -96,8 +94,10 @@ void CarbonProtocolReader::skip(const FieldType ft) {
skipKVContainer();
break;
}
default: { break; }
default: {
break;
}
}
}

} // carbon
} // namespace carbon
6 changes: 4 additions & 2 deletions mcrouter/lib/carbon/CarbonProtocolReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ class CarbonProtocolReader {
}

void readStructEnd() {
lastFieldId_ = nestedStructFieldIds_.back();
nestedStructFieldIds_.pop_back();
if (!nestedStructFieldIds_.empty()) {
lastFieldId_ = nestedStructFieldIds_.back();
nestedStructFieldIds_.pop_back();
}
}

std::pair<std::pair<FieldType, FieldType>, uint32_t>
Expand Down

0 comments on commit 97e033b

Please sign in to comment.