@@ -55,8 +55,7 @@ namespace flatbuffers = flatbuffers_fbsource;
55
55
#include < torch/csrc/jit/serialization/mobile_bytecode_generated.h> // NOLINT
56
56
#endif
57
57
58
- namespace torch {
59
- namespace jit {
58
+ namespace torch ::jit {
60
59
61
60
// Our own alignment requirement does not need to be exactly the same as what
62
61
// flatbuffers supports, but what flatbuffers supports needs to satisfy our
@@ -91,9 +90,9 @@ class FlatbufferLoader final {
91
90
ExtraFilesMap* jit_sources,
92
91
std::vector<IValue>* constants);
93
92
94
- typedef TypePtr (*TypeResolver )(
93
+ using TypeResolver = TypePtr (*)(
95
94
const std::string& type_str,
96
- std::shared_ptr<CompilationUnit> cu);
95
+ const std::shared_ptr<CompilationUnit>& cu);
97
96
98
97
void internal_registerTypeResolver (TypeResolver type_resolver);
99
98
@@ -187,7 +186,7 @@ IValue parseEnum(
187
186
188
187
TypePtr resolveType (
189
188
const std::string& type_string,
190
- std::shared_ptr<CompilationUnit> cu) {
189
+ const std::shared_ptr<CompilationUnit>& cu) {
191
190
TypePtr type;
192
191
c10::string_view type_str (type_string);
193
192
if (type_str.starts_with (kCustomClassPrefix )) {
@@ -531,7 +530,7 @@ IValue parseList(
531
530
const mobile::serialization::IValue& ivalue) {
532
531
const mobile::serialization::List* list = ivalue.val_as_List ();
533
532
auto res = c10::impl::GenericList (AnyType::get ());
534
- for (int i : *list->items ()) {
533
+ for (auto i : *list->items ()) {
535
534
res.emplace_back (loader.getIValue (i));
536
535
}
537
536
auto type = loader.getOrCreateTypeAnnotations (list->annotation_str ());
@@ -575,11 +574,13 @@ IValue parseTuple(
575
574
FlatbufferLoader& loader,
576
575
const mobile::serialization::IValue& ivalue) {
577
576
const auto & tuple = ivalue.val_as_Tuple ();
577
+ const auto items = tuple->items ();
578
578
std::vector<IValue> res;
579
- for (int i : *tuple->items ()) {
579
+ res.reserve (items->size ());
580
+ for (auto i : *items) {
580
581
res.emplace_back (loader.getIValue (i));
581
582
}
582
- return c10::ivalue::Tuple::create (res);
583
+ return c10::ivalue::Tuple::create (std::move ( res) );
583
584
}
584
585
585
586
IValue parseDict (
@@ -939,5 +940,4 @@ bool register_flatbuffer_loader() {
939
940
return true ;
940
941
}
941
942
942
- } // namespace jit
943
- } // namespace torch
943
+ } // namespace torch::jit
0 commit comments