Skip to content

Commit 4893a62

Browse files
committed
YTORM: Use (From|To)Proto methods from yt/yt/core
commit_hash:73c27f665b4988fbc1db7e192fc14aa22125f76c
1 parent bec56a4 commit 4893a62

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

yt/yt/core/misc/protobuf_helpers-inl.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ void ToProto(
486486
{
487487
serializedMap->clear();
488488
for (const auto& [key, value] : originalMap) {
489-
auto [_, inserted] = serializedMap->insert(std::pair(ToProto<TSerializedKey>(key), ToProto<TSerializedValue>(value)));
490-
if (!inserted) {
489+
auto [_, emplaced] = serializedMap->emplace(ToProto<TSerializedKey>(key), ToProto<TSerializedValue>(value));
490+
if (!emplaced) {
491491
THROW_ERROR_EXCEPTION("Found duplicate key during protobuf map serialization")
492492
<< TErrorAttribute("key", key)
493493
<< TErrorAttribute("serialized_key", ToProto<TSerializedKey>(key));
@@ -537,10 +537,12 @@ void FromProto(
537537
const ::google::protobuf::Map<TSerializedKey, TSerializedValue>& serializedMap)
538538
{
539539
originalMap->clear();
540+
originalMap->reserve(serializedMap.size());
540541
for (const auto& [serializedKey, serializedValue] : serializedMap) {
541-
auto [_, inserted] = originalMap->emplace(FromProto<TKey>(serializedKey), FromProto<TValue>(serializedValue));
542-
if (!inserted) {
542+
auto [_, emplaced] = originalMap->emplace(FromProto<TKey>(serializedKey), FromProto<TValue>(serializedValue));
543+
if (!emplaced) {
543544
THROW_ERROR_EXCEPTION("Found duplicate key during protobuf map deserialization")
545+
<< TErrorAttribute("serialized_key", serializedKey)
544546
<< TErrorAttribute("key", FromProto<TKey>(serializedKey));
545547
}
546548
}

0 commit comments

Comments
 (0)