diff options
author | ifsmirnov <ifsmirnov@yandex-team.com> | 2023-09-13 17:02:44 +0300 |
---|---|---|
committer | ifsmirnov <ifsmirnov@yandex-team.com> | 2023-09-13 19:44:17 +0300 |
commit | 093621907f2892c5fa52ad8e54c45d3c56690554 (patch) | |
tree | 8227f4484e860f93c749c34b8e620060a06f2f1b | |
parent | 984bb4059ca09282012c669b6be5f97cf87af0cc (diff) | |
download | ydb-093621907f2892c5fa52ad8e54c45d3c56690554.tar.gz |
Introduce DECLARE_YSON_STRUCT to speed up compilation
-rw-r--r-- | yt/yt/core/ytree/yson_struct-inl.h | 70 | ||||
-rw-r--r-- | yt/yt/core/ytree/yson_struct.h | 50 |
2 files changed, 90 insertions, 30 deletions
diff --git a/yt/yt/core/ytree/yson_struct-inl.h b/yt/yt/core/ytree/yson_struct-inl.h index 5ea9b17c0d3..7e375d995f0 100644 --- a/yt/yt/core/ytree/yson_struct-inl.h +++ b/yt/yt/core/ytree/yson_struct-inl.h @@ -293,4 +293,74 @@ void UpdateYsonStructField(TIntrusivePtr<TDst>& dst, const TIntrusivePtr<TSrc>& //////////////////////////////////////////////////////////////////////////////// +#undef DECLARE_YSON_STRUCT +#undef REGISTER_YSON_STRUCT +#undef DECLARE_YSON_STRUCT_LITE +#undef REGISTER_YSON_STRUCT_LITE +#undef DEFINE_YSON_STRUCT + + +#define YSON_STRUCT_IMPL__DECLARE_ALIASES(TStruct) \ +private: \ + using TRegistrar = ::NYT::NYTree::TYsonStructRegistrar<TStruct>; \ + using TThis = TStruct; \ + friend class ::NYT::NYTree::TYsonStructRegistry; + +#define YSON_STRUCT_IMPL__CTOR_BODY(TStruct) \ + ::NYT::NYTree::TYsonStructRegistry::Get()->InitializeStruct(this); + + +#define DECLARE_YSON_STRUCT(TStruct) \ +public: \ + TStruct(); \ + YSON_STRUCT_IMPL__DECLARE_ALIASES(TStruct) + +#define REGISTER_YSON_STRUCT(TStruct) \ +public: \ + TStruct() \ + { \ + YSON_STRUCT_IMPL__CTOR_BODY(TStruct) \ + } \ + YSON_STRUCT_IMPL__DECLARE_ALIASES(TStruct) + + +#define REGISTER_YSON_STRUCT_LITE_BASE(TStruct) \ +public: \ + static TStruct Create() \ + { \ + static_assert(std::is_base_of_v<::NYT::NYTree::TYsonStructLite, TStruct>, "Class must inherit from TYsonStructLite"); \ + TStruct result; \ + result.SetDefaults(); \ + return result; \ + } \ + \ + template <class T> \ + friend const std::type_info& ::NYT::NYTree::CallCtor(); \ + \ + YSON_STRUCT_IMPL__DECLARE_ALIASES(TStruct) \ + +#define DECLARE_YSON_STRUCT_LITE(TStruct) \ + REGISTER_YSON_STRUCT_LITE_BASE(TStruct) \ + \ +protected: \ + TStruct(); + +#define REGISTER_YSON_STRUCT_LITE(TStruct) \ + REGISTER_YSON_STRUCT_LITE_BASE(TStruct) \ + \ +protected: \ + TStruct() \ + { \ + YSON_STRUCT_IMPL__CTOR_BODY(TStruct) \ + } + + +#define DEFINE_YSON_STRUCT(TStruct) \ +TStruct::TStruct() \ +{ \ + YSON_STRUCT_IMPL__CTOR_BODY(TStruct) \ +} + +//////////////////////////////////////////////////////////////////////////////// + } // namespace NYT::NYTree diff --git a/yt/yt/core/ytree/yson_struct.h b/yt/yt/core/ytree/yson_struct.h index 54b10d19934..12ec7f871d2 100644 --- a/yt/yt/core/ytree/yson_struct.h +++ b/yt/yt/core/ytree/yson_struct.h @@ -40,6 +40,10 @@ namespace NYT::NYTree { * Non-ref-counted structs are initialized in factory method TYourClass::Create() * which is generated by the macro REGISTER_YSON_STRUCT_LITE. * + * In order to speed up compilation it is possible to use DECLARE_YSON_STRUCT(TYourClass) in the class body + * and supplement it with DEFINE_YSON_STRUCT(TYourClass) in the .cpp file. Similar DECLARE_YSON_STRUCT_LITE + * macro is available for non-ref-counted structs. + * * The key difference from TYsonSerializable is that the latter builds the whole meta every time * an instance of the class is being constructed * while TYsonStruct builds meta only once just before construction of the first instance. @@ -248,36 +252,22 @@ void UpdateYsonStructField(TIntrusivePtr<TDst>& dst, const TIntrusivePtr<TSrc>& //////////////////////////////////////////////////////////////////////////////// -#define REGISTER_YSON_STRUCT_IMPL(TStruct) \ - TStruct() \ - { \ - ::NYT::NYTree::TYsonStructRegistry::Get()->InitializeStruct(this); \ - } \ - \ -private: \ - using TRegistrar = ::NYT::NYTree::TYsonStructRegistrar<TStruct>; \ - using TThis = TStruct; \ - friend class ::NYT::NYTree::TYsonStructRegistry - -#define REGISTER_YSON_STRUCT(TStruct) \ -public: \ -REGISTER_YSON_STRUCT_IMPL(TStruct) - -#define REGISTER_YSON_STRUCT_LITE(TStruct) \ -public: \ - \ - static TStruct Create() { \ - static_assert(std::is_base_of_v<::NYT::NYTree::TYsonStructLite, TStruct>, "Class must inherit from TYsonStructLite"); \ - TStruct result; \ - result.SetDefaults(); \ - return result; \ - } \ - \ -template <class T> \ -friend const std::type_info& ::NYT::NYTree::CallCtor(); \ - \ -protected: \ -REGISTER_YSON_STRUCT_IMPL(TStruct) +//! Declare Yson Struct auxiliary methods and fields. Must be supplemented +//! by DEFINE_YSON_STRUCT. +#define DECLARE_YSON_STRUCT(TStruct) + +//! Declare Yson Struct auxiliary methods and define them inplace. +#define REGISTER_YSON_STRUCT(TStruct) + +//! Declare non-ref-counted Yson Struct auxiliary methods and fields. Must be +//! supplemented by DEFINE_YSON_STRUCT. +#define DECLARE_YSON_STRUCT_LITE(TStruct) + +//! Declare non-ref-counted Yson Struct auxiliary methods and define them inplace. +#define REGISTER_YSON_STRUCT_LITE(TStruct) + +//! Define Yson Struct auxiliary methods out of class. +#define DEFINE_YSON_STRUCT(TStruct) //////////////////////////////////////////////////////////////////////////////// |