-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Changed the way how enums generated in thrift-py3: 1. Use C++ map to store name to unique Enum Python instances cache 2. Dynamically find instances from cache (or create one and add to cache) instead of populating all instances at module load time 3. use `__getattr__` and `__getitem__` instead of code-gen all the getters Reviewed By: asp2insp Differential Revision: D23182622 fbshipit-source-id: 75baef997ee2d604b4ef7606f282cfc3306208ac
- Loading branch information
1 parent
0580653
commit b974229
Showing
130 changed files
with
2,611 additions
and
4,473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{{! | ||
Copyright (c) Facebook, Inc. and its affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
}}{{! | ||
C++ header to store py3 specific Enum and Union type enum data | ||
}} | ||
{{> common/AutoGeneratedC}} | ||
|
||
#pragma once | ||
|
||
#include <thrift/lib/py3/enums.h> | ||
#include "{{program:includePrefix}}gen-cpp2/{{program:name}}_types.h" | ||
{{#program:enums}} | ||
|
||
template<> | ||
const std::vector<std::pair<std::string_view, std::string_view>>& ::thrift::py3::PyEnumTraits< | ||
{{#program:cppNamespaces}}::{{value}}{{/program:cppNamespaces}}::{{enum:name}}>::namesmap() { | ||
static const folly::Indestructible<NamesMap> pairs { | ||
{ | ||
{{#enum:values}}{{#enumValue:hasPyName?}} | ||
{"{{enumValue:py_name}}", "{{enumValue:name}}"}, | ||
{{/enumValue:hasPyName?}}{{/enum:values}} | ||
} | ||
}; | ||
return *pairs; | ||
} | ||
|
||
{{/program:enums}} | ||
{{#program:structs}} | ||
{{#struct:union?}} | ||
|
||
template<> | ||
const std::vector<std::pair<std::string_view, std::string_view>>& ::thrift::py3::PyEnumTraits< | ||
{{#program:cppNamespaces}}::{{value}}{{/program:cppNamespaces}}::{{struct:name}}::Type>::namesmap() { | ||
static const folly::Indestructible<NamesMap> pairs { | ||
{ | ||
{{#struct:fields}}{{#field:hasPyName?}} | ||
{"{{field:py_name}}", "{{field:name}}"}, | ||
{{/field:hasPyName?}}{{/struct:fields}} | ||
} | ||
}; | ||
return *pairs; | ||
} | ||
{{/struct:union?}} | ||
{{/program:structs}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.