mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[caffe2] tweak Unpickler::readInstruction handling TUPLE (#164764)
Summary: Creating the vector was a bit awkward. Use the natural iterator-pair constructor with move-iterators. Test Plan: CI. Reviewed By: dolpm Differential Revision: D83995108 Pull Request resolved: https://github.com/pytorch/pytorch/pull/164764 Approved by: https://github.com/drisspg
This commit is contained in:
committed by
PyTorch MergeBot
parent
44a5d41993
commit
d4752bc7f6
@ -351,7 +351,6 @@ PickleOpCode Unpickler::readInstruction() {
|
||||
TORCH_CHECK(!marks_.empty(), "Parsing error: marks_ is empty");
|
||||
size_t start = marks_.back();
|
||||
marks_.pop_back();
|
||||
std::vector<IValue> elements;
|
||||
TORCH_CHECK(
|
||||
stack_.size() >= start,
|
||||
"Parsing error: wrong start index ",
|
||||
@ -379,11 +378,10 @@ PickleOpCode Unpickler::readInstruction() {
|
||||
stack_.emplace_back(c10::ivalue::Tuple::create(pop(stack_)));
|
||||
break;
|
||||
default: {
|
||||
elements.reserve(stack_.size() - start);
|
||||
auto start_it = stack_.begin() + static_cast<std::ptrdiff_t>(start);
|
||||
for (auto it = start_it; it != stack_.end(); ++it) {
|
||||
elements.emplace_back(std::move(*it));
|
||||
}
|
||||
std::vector<IValue> elements{
|
||||
std::make_move_iterator(start_it),
|
||||
std::make_move_iterator(stack_.end())};
|
||||
stack_.erase(start_it, stack_.end());
|
||||
stack_.emplace_back(c10::ivalue::Tuple::create(std::move(elements)));
|
||||
break;
|
||||
|
Reference in New Issue
Block a user