mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[PyTorch] Avoid extra std::vector in parseSchemaOrName (#64678)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/64678 We know we only want one declaration, so let's not create an excess std::vector (and thus a heap allocation) for that. ghstack-source-id: 138036978 Test Plan: CI Reviewed By: dhruvbird, tugsbayasgalan Differential Revision: D30813785 fbshipit-source-id: c67e0100cdef5d894282939fb6d39a57309bc240
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0f1bccb692
commit
bdbc622988
@ -122,6 +122,13 @@ struct SchemaParser {
|
||||
return results;
|
||||
}
|
||||
|
||||
either<OperatorName, FunctionSchema> parseExactlyOneDeclaration() {
|
||||
auto result = parseDeclaration();
|
||||
L.nextIf(TK_NEWLINE);
|
||||
L.expect(TK_EOF);
|
||||
return result;
|
||||
}
|
||||
|
||||
Argument parseArgument(size_t idx, bool is_return, bool kwarg_only) {
|
||||
auto p = type_parser.parseType();
|
||||
auto type = std::move(p.first);
|
||||
@ -319,7 +326,7 @@ struct SchemaParser {
|
||||
|
||||
C10_EXPORT either<OperatorName, FunctionSchema> parseSchemaOrName(
|
||||
const std::string& schemaOrName) {
|
||||
return SchemaParser(schemaOrName).parseDeclarations().at(0);
|
||||
return SchemaParser(schemaOrName).parseExactlyOneDeclaration();
|
||||
}
|
||||
|
||||
C10_EXPORT FunctionSchema parseSchema(const std::string& schema) {
|
||||
|
Reference in New Issue
Block a user