Skip to content

Commit fd0d7fe

Browse files
author
babenko
committed
YT-22593: Migrate Yson Struct to std::string
commit_hash:835651ea93912dc3740a84bf06c3dc17ba166ea8
1 parent 63e9f6a commit fd0d7fe

File tree

8 files changed

+68
-68
lines changed

8 files changed

+68
-68
lines changed

yt/yt/core/ytree/yson_struct-inl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@ TYsonStructRegistrar<TStruct>::TYsonStructRegistrar(IYsonStructMeta* meta)
171171

172172
template <class TStruct>
173173
template <class TValue>
174-
TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::Parameter(const TString& key, TValue(TStruct::*field))
174+
TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::Parameter(const std::string& key, TValue(TStruct::*field))
175175
{
176176
return BaseClassParameter<TStruct, TValue>(key, field);
177177
}
178178

179179
template <class TStruct>
180180
template <class TBase, class TValue>
181-
TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::BaseClassParameter(const TString& key, TValue(TBase::*field))
181+
TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::BaseClassParameter(const std::string& key, TValue(TBase::*field))
182182
{
183183
static_assert(std::derived_from<TStruct, TBase>);
184184
int fieldIndex = ssize(Meta_->GetParameterMap());
@@ -189,7 +189,7 @@ TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::BaseClassParameter(
189189

190190
template <class TStruct>
191191
template <class TValue>
192-
TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::ParameterWithUniversalAccessor(const TString& key, std::function<TValue&(TStruct*)> accessor)
192+
TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::ParameterWithUniversalAccessor(const std::string& key, std::function<TValue&(TStruct*)> accessor)
193193
{
194194
int fieldIndex = ssize(Meta_->GetParameterMap());
195195
auto parameter = New<TYsonStructParameter<TValue>>(key, std::make_unique<TUniversalYsonParameterAccessor<TStruct, TValue>>(std::move(accessor)), fieldIndex);
@@ -216,7 +216,7 @@ void TYsonStructRegistrar<TStruct>::Postprocessor(std::function<void(TStruct*)>
216216
template <class TStruct>
217217
template <class TExternal, class TValue>
218218
// requires std::derived_from<TStruct, TExternalizedYsonStruct<TExternal, TStruct>>
219-
TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::ExternalClassParameter(const TString& key, TValue(TExternal::*field))
219+
TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::ExternalClassParameter(const std::string& key, TValue(TExternal::*field))
220220
{
221221
static_assert(std::derived_from<TStruct, TExternalizedYsonStruct>);
222222
static_assert(std::same_as<typename TStruct::TExternal, TExternal>);
@@ -251,7 +251,7 @@ void TYsonStructRegistrar<TStruct>::ExternalPostprocessor(TExternalPostprocessor
251251

252252
template <class TStruct>
253253
template <class TBase, class TValue>
254-
TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::ExternalBaseClassParameter(const TString& key, TValue(TBase::*field))
254+
TYsonStructParameter<TValue>& TYsonStructRegistrar<TStruct>::ExternalBaseClassParameter(const std::string& key, TValue(TBase::*field))
255255
{
256256
static_assert(std::derived_from<TStruct, TExternalizedYsonStruct>);
257257
static_assert(std::derived_from<typename TStruct::TExternal, TBase>);
@@ -338,7 +338,7 @@ THashMap<TKey, TIntrusivePtr<TValue>> CloneYsonStructs(const THashMap<TKey, TInt
338338
clonedObjs.reserve(objs.size());
339339
for (const auto& [key, obj] : objs) {
340340
// TODO(babenko): switch to std::string
341-
clonedObjs.emplace(TString(key), CloneYsonStruct(obj));
341+
clonedObjs.emplace(std::string(key), CloneYsonStruct(obj));
342342
}
343343
return clonedObjs;
344344
}

yt/yt/core/ytree/yson_struct.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void TYsonStructBase::SetUnrecognizedStrategy(EUnrecognizedStrategy strategy)
5555
InstanceUnrecognizedStrategy_ = strategy;
5656
}
5757

58-
THashSet<TString> TYsonStructBase::GetRegisteredKeys() const
58+
THashSet<std::string> TYsonStructBase::GetRegisteredKeys() const
5959
{
6060
return Meta_->GetRegisteredKeys();
6161
}
@@ -128,17 +128,17 @@ void TYsonStructBase::SetDefaults()
128128
Meta_->SetDefaultsOfInitializedStruct(this);
129129
}
130130

131-
void TYsonStructBase::SaveParameter(const TString& key, IYsonConsumer* consumer) const
131+
void TYsonStructBase::SaveParameter(const std::string& key, IYsonConsumer* consumer) const
132132
{
133133
Meta_->GetParameter(key)->Save(this, consumer);
134134
}
135135

136-
void TYsonStructBase::LoadParameter(const TString& key, const NYTree::INodePtr& node)
136+
void TYsonStructBase::LoadParameter(const std::string& key, const NYTree::INodePtr& node)
137137
{
138138
Meta_->LoadParameter(this, key, node);
139139
}
140140

141-
void TYsonStructBase::ResetParameter(const TString& key)
141+
void TYsonStructBase::ResetParameter(const std::string& key)
142142
{
143143
Meta_->GetParameter(key)->SetDefaultsInitialized(this);
144144
}
@@ -148,7 +148,7 @@ int TYsonStructBase::GetParameterCount() const
148148
return Meta_->GetParameterMap().size();
149149
}
150150

151-
std::vector<TString> TYsonStructBase::GetAllParameterAliases(const TString& key) const
151+
std::vector<std::string> TYsonStructBase::GetAllParameterAliases(const std::string& key) const
152152
{
153153
auto parameter = Meta_->GetParameter(key);
154154
auto result = parameter->GetAliases();
@@ -181,7 +181,7 @@ void TYsonStruct::InitializeRefCounted()
181181
}
182182
}
183183

184-
bool TYsonStruct::IsSet(const TString& key) const
184+
bool TYsonStruct::IsSet(const std::string& key) const
185185
{
186186
return SetFields_[Meta_->GetParameter(key)->GetFieldIndex()];
187187
}
@@ -200,7 +200,7 @@ TCompactBitmap* TYsonStructLite::GetSetFieldsBitmap()
200200

201201
////////////////////////////////////////////////////////////////////////////////
202202

203-
bool TYsonStructLiteWithFieldTracking::IsSet(const TString& key) const
203+
bool TYsonStructLiteWithFieldTracking::IsSet(const std::string& key) const
204204
{
205205
return SetFields_[Meta_->GetParameter(key)->GetFieldIndex()];
206206
}

yt/yt/core/ytree/yson_struct.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ class TYsonStructBase
9797

9898
void SetUnrecognizedStrategy(EUnrecognizedStrategy strategy);
9999

100-
THashSet<TString> GetRegisteredKeys() const;
100+
THashSet<std::string> GetRegisteredKeys() const;
101101
int GetParameterCount() const;
102102

103103
// TODO(renadeen): remove this methods.
104-
void SaveParameter(const TString& key, NYson::IYsonConsumer* consumer) const;
105-
void LoadParameter(const TString& key, const NYTree::INodePtr& node);
106-
void ResetParameter(const TString& key);
104+
void SaveParameter(const std::string& key, NYson::IYsonConsumer* consumer) const;
105+
void LoadParameter(const std::string& key, const NYTree::INodePtr& node);
106+
void ResetParameter(const std::string& key);
107107

108-
std::vector<TString> GetAllParameterAliases(const TString& key) const;
108+
std::vector<std::string> GetAllParameterAliases(const std::string& key) const;
109109

110110
void WriteSchema(NYson::IYsonConsumer* consumer) const;
111111

@@ -149,7 +149,7 @@ class TYsonStruct
149149
public:
150150
void InitializeRefCounted();
151151

152-
bool IsSet(const TString& key) const;
152+
bool IsSet(const std::string& key) const;
153153

154154
private:
155155
TCompactBitmap SetFields_;
@@ -192,7 +192,7 @@ class TYsonStructLiteWithFieldTracking
192192
TYsonStructLiteWithFieldTracking(TYsonStructLiteWithFieldTracking&& other) = default;
193193
TYsonStructLiteWithFieldTracking& operator=(TYsonStructLiteWithFieldTracking&& other) = default;
194194

195-
bool IsSet(const TString& key) const;
195+
bool IsSet(const std::string& key) const;
196196

197197
private:
198198
TCompactBitmap SetFields_;
@@ -326,13 +326,13 @@ class TYsonStructRegistrar
326326
explicit TYsonStructRegistrar(IYsonStructMeta* meta);
327327

328328
template <class TValue>
329-
TYsonStructParameter<TValue>& Parameter(const TString& key, TValue(TStruct::*field));
329+
TYsonStructParameter<TValue>& Parameter(const std::string& key, TValue(TStruct::*field));
330330

331331
template <class TBase, class TValue>
332-
TYsonStructParameter<TValue>& BaseClassParameter(const TString& key, TValue(TBase::*field));
332+
TYsonStructParameter<TValue>& BaseClassParameter(const std::string& key, TValue(TBase::*field));
333333

334334
template <class TValue>
335-
TYsonStructParameter<TValue>& ParameterWithUniversalAccessor(const TString& key, std::function<TValue&(TStruct*)> accessor);
335+
TYsonStructParameter<TValue>& ParameterWithUniversalAccessor(const std::string& key, std::function<TValue&(TStruct*)> accessor);
336336

337337
void Preprocessor(std::function<void(TStruct*)> preprocessor);
338338

@@ -352,10 +352,10 @@ class TYsonStructRegistrar
352352

353353
template <class TExternal, class TValue>
354354
// requires std::derived_from<TStruct, TExternalizedYsonStruct<TExternal, TStruct>>
355-
TYsonStructParameter<TValue>& ExternalClassParameter(const TString& key, TValue(TExternal::*field));
355+
TYsonStructParameter<TValue>& ExternalClassParameter(const std::string& key, TValue(TExternal::*field));
356356

357357
template <class TBase, class TValue>
358-
TYsonStructParameter<TValue>& ExternalBaseClassParameter(const TString& key, TValue(TBase::*field));
358+
TYsonStructParameter<TValue>& ExternalBaseClassParameter(const std::string& key, TValue(TBase::*field));
359359

360360
template <class TExternalPreprocessor>
361361
// requires (CInvocable<TExternalPreprocessor, void(typename TStruct::TExternal*)>)

yt/yt/core/ytree/yson_struct_detail-inl.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ struct TYsonSourceTraits<NYson::TYsonPullParserCursor*>
188188
static void FillMap(NYson::TYsonPullParserCursor*& source, TMap& map, TFiller filler)
189189
{
190190
source->ParseMap([&] (NYson::TYsonPullParserCursor* cursor) {
191-
auto key = ExtractTo<TString>(cursor);
191+
auto key = ExtractTo<std::string>(cursor);
192192
filler(map, std::move(key), source);
193193
});
194194
}
@@ -439,7 +439,7 @@ void LoadFromSource(
439439
using TValue = typename TMap::mapped_type;
440440

441441
try {
442-
TTraits::FillMap(source, parameter, [&] (TMap& map, const TString& key, auto childSource) {
442+
TTraits::FillMap(source, parameter, [&] (TMap& map, const std::string& key, auto childSource) {
443443
TValue value;
444444
LoadFromSource(
445445
value,
@@ -785,7 +785,7 @@ TValue& TUniversalYsonParameterAccessor<TStruct, TValue>::GetValue(const TYsonSt
785785

786786
template <class TValue>
787787
TYsonStructParameter<TValue>::TYsonStructParameter(
788-
TString key,
788+
std::string key,
789789
std::unique_ptr<IYsonFieldAccessor<TValue>> fieldAccessor,
790790
int fieldIndex)
791791
: Key_(std::move(key))
@@ -942,7 +942,7 @@ bool TYsonStructParameter<TValue>::CanOmitValue(const TYsonStructBase* self) con
942942
}
943943

944944
template <class TValue>
945-
TYsonStructParameter<TValue>& TYsonStructParameter<TValue>::Alias(const TString& name)
945+
TYsonStructParameter<TValue>& TYsonStructParameter<TValue>::Alias(const std::string& name)
946946
{
947947
Aliases_.push_back(name);
948948
return *this;
@@ -970,7 +970,7 @@ TYsonStructParameter<TValue>& TYsonStructParameter<TValue>::EnforceDefaultUnreco
970970
}
971971

972972
template <class TValue>
973-
const std::vector<TString>& TYsonStructParameter<TValue>::GetAliases() const
973+
const std::vector<std::string>& TYsonStructParameter<TValue>::GetAliases() const
974974
{
975975
return Aliases_;
976976
}
@@ -982,7 +982,7 @@ bool TYsonStructParameter<TValue>::IsRequired() const
982982
}
983983

984984
template <class TValue>
985-
const TString& TYsonStructParameter<TValue>::GetKey() const
985+
const std::string& TYsonStructParameter<TValue>::GetKey() const
986986
{
987987
return Key_;
988988
}
@@ -1029,7 +1029,7 @@ TYsonStructParameter<TValue>& TYsonStructParameter<TValue>::DontSerializeDefault
10291029
// to do the deep validation.
10301030
static_assert(
10311031
NPrivate::CSupportsDontSerializeDefault<TValue>,
1032-
"DontSerializeDefault requires |Parameter| to be TString, TDuration, an arithmetic type or an optional of those");
1032+
"DontSerializeDefault requires |Parameter| to be std::string, TDuration, an arithmetic type or an optional of those");
10331033

10341034
SerializeDefault_ = false;
10351035
return *this;

yt/yt/core/ytree/yson_struct_detail.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ void TYsonStructMeta::SetDefaultsOfInitializedStruct(TYsonStructBase* target) co
4242
}
4343
}
4444

45-
const THashSet<TString>& TYsonStructMeta::GetRegisteredKeys() const
45+
const THashSet<std::string>& TYsonStructMeta::GetRegisteredKeys() const
4646
{
4747
return RegisteredKeys_;
4848
}
4949

50-
const THashMap<TString, IYsonStructParameterPtr>& TYsonStructMeta::GetParameterMap() const
50+
const THashMap<std::string, IYsonStructParameterPtr>& TYsonStructMeta::GetParameterMap() const
5151
{
5252
return Parameters_;
5353
}
5454

55-
const std::vector<std::pair<TString, IYsonStructParameterPtr>>& TYsonStructMeta::GetParameterSortedList() const
55+
const std::vector<std::pair<std::string, IYsonStructParameterPtr>>& TYsonStructMeta::GetParameterSortedList() const
5656
{
5757
return SortedParameters_;
5858
}
5959

60-
IYsonStructParameterPtr TYsonStructMeta::GetParameter(const TString& keyOrAlias) const
60+
IYsonStructParameterPtr TYsonStructMeta::GetParameter(const std::string& keyOrAlias) const
6161
{
6262
auto it = Parameters_.find(keyOrAlias);
6363
if (it != Parameters_.end()) {
@@ -72,7 +72,7 @@ IYsonStructParameterPtr TYsonStructMeta::GetParameter(const TString& keyOrAlias)
7272
THROW_ERROR_EXCEPTION("Key or alias %Qv not found in yson struct", keyOrAlias);
7373
}
7474

75-
void TYsonStructMeta::LoadParameter(TYsonStructBase* target, const TString& key, const NYTree::INodePtr& node) const
75+
void TYsonStructMeta::LoadParameter(TYsonStructBase* target, const std::string& key, const NYTree::INodePtr& node) const
7676
{
7777
const auto& parameter = GetParameter(key);
7878
auto validate = [&] {
@@ -130,7 +130,7 @@ void TYsonStructMeta::LoadStruct(
130130
auto mapNode = node->AsMap();
131131
auto unrecognizedStrategy = target->InstanceUnrecognizedStrategy_.template value_or(MetaUnrecognizedStrategy_);
132132
for (const auto& [name, parameter] : SortedParameters_) {
133-
TString key = name;
133+
std::string key = name;
134134
auto child = mapNode->FindChild(name); // can be NULL
135135
for (const auto& alias : parameter->GetAliases()) {
136136
auto otherChild = mapNode->FindChild(alias);
@@ -207,7 +207,7 @@ void TYsonStructMeta::LoadStruct(
207207
InsertOrCrash(pendingParameters, parameter.Get());
208208
}
209209

210-
THashMap<TString, TString> aliasedData;
210+
THashMap<std::string, std::string> aliasedData;
211211

212212
auto processPossibleAlias = [&] (
213213
IYsonStructParameter* parameter,
@@ -241,7 +241,7 @@ void TYsonStructMeta::LoadStruct(
241241
EmplaceOrCrash(aliasedData, canonicalKey, std::move(data));
242242
};
243243

244-
auto processUnrecognized = [&] (const TString& key, NYson::TYsonPullParserCursor* cursor) {
244+
auto processUnrecognized = [&] (const std::string& key, NYson::TYsonPullParserCursor* cursor) {
245245
if (unrecognizedStrategy == EUnrecognizedStrategy::Drop) {
246246
cursor->SkipComplexValue();
247247
return;
@@ -260,7 +260,7 @@ void TYsonStructMeta::LoadStruct(
260260
};
261261

262262
cursor->ParseMap([&] (NYson::TYsonPullParserCursor* cursor) {
263-
auto key = ExtractTo<TString>(cursor);
263+
auto key = ExtractTo<std::string>(cursor);
264264
auto it = keyToParameter.find(key);
265265
if (it == keyToParameter.end()) {
266266
processUnrecognized(key, cursor);
@@ -304,7 +304,7 @@ IMapNodePtr TYsonStructMeta::GetRecursiveUnrecognized(const TYsonStructBase* tar
304304
return result;
305305
}
306306

307-
void TYsonStructMeta::RegisterParameter(TString key, IYsonStructParameterPtr parameter)
307+
void TYsonStructMeta::RegisterParameter(std::string key, IYsonStructParameterPtr parameter)
308308
{
309309
YT_VERIFY(Parameters_.template emplace(std::move(key), std::move(parameter)).second);
310310
}
@@ -356,7 +356,7 @@ void TYsonStructMeta::FinishInitialization(const std::type_info& structType)
356356
}
357357
}
358358

359-
SortedParameters_ = std::vector<std::pair<TString, IYsonStructParameterPtr>>(Parameters_.begin(), Parameters_.end());
359+
SortedParameters_ = std::vector<std::pair<std::string, IYsonStructParameterPtr>>(Parameters_.begin(), Parameters_.end());
360360
std::sort(
361361
SortedParameters_.begin(),
362362
SortedParameters_.end(),

0 commit comments

Comments
 (0)