Skip to content

Commit b734377

Browse files
committed
cc userver: use designated initialization where possible
commit_hash:7a2e9484bf8892257d5adce04fd39f238247b151
1 parent 043fe61 commit b734377

69 files changed

Lines changed: 580 additions & 548 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/include/userver/cache/expirable_lru_cache.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ template <typename Value>
4242
impl::ExpirableValue<Value> Read(dump::Reader& reader, dump::To<impl::ExpirableValue<Value>>) {
4343
const auto [now, steady_now] = utils::impl::GetGlobalTime();
4444
// Evaluation order of arguments is guaranteed in brace-initialization.
45-
return impl::ExpirableValue<
46-
Value>{reader.Read<Value>(), reader.Read<std::chrono::system_clock::time_point>() - now + steady_now};
45+
return impl::ExpirableValue<Value>{
46+
.value = reader.Read<Value>(),
47+
.update_time = reader.Read<std::chrono::system_clock::time_point>() - now + steady_now,
48+
};
4749
}
4850

4951
} // namespace impl
@@ -299,7 +301,7 @@ Value ExpirableLruCache<
299301

300302
auto value = update_func(key);
301303
if (read_mode == ReadMode::kUseCache) {
302-
lru_.Put(key, {value, now});
304+
lru_.Put(key, {.value = value, .update_time = now});
303305
}
304306
return value;
305307
}
@@ -398,12 +400,12 @@ std::optional<Value> ExpirableLruCache<Key, Value, Hash, Equal>::GetOptionalNoUp
398400

399401
template <typename Key, typename Value, typename Hash, typename Equal>
400402
void ExpirableLruCache<Key, Value, Hash, Equal>::Put(const Key& key, const Value& value) {
401-
lru_.Put(key, {value, utils::datetime::SteadyNow()});
403+
lru_.Put(key, {.value = value, .update_time = utils::datetime::SteadyNow()});
402404
}
403405

404406
template <typename Key, typename Value, typename Hash, typename Equal>
405407
void ExpirableLruCache<Key, Value, Hash, Equal>::Put(const Key& key, Value&& value) {
406-
lru_.Put(key, {std::move(value), utils::datetime::SteadyNow()});
408+
lru_.Put(key, {.value = std::move(value), .update_time = utils::datetime::SteadyNow()});
407409
}
408410

409411
template <typename Key, typename Value, typename Hash, typename Equal>
@@ -456,7 +458,7 @@ void ExpirableLruCache<Key, Value, Hash, Equal>::UpdateInBackground(const Key& k
456458

457459
auto now = utils::datetime::SteadyNow();
458460
auto value = update_func(key);
459-
lru_.Put(key, {value, now});
461+
lru_.Put(key, {.value = value, .update_time = now});
460462
})
461463
);
462464
}

core/include/userver/concurrent/mutex_set.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ ItemMutex<Key, Equal> MutexSet<Key, Hash, Equal>::GetMutexForKey(Key key) {
112112
const auto way = hash_value % size;
113113
const auto new_hash = hash_value / size;
114114

115-
return ItemMutex<Key, Equal>(mutex_data_[way], {new_hash, std::move(key)});
115+
return ItemMutex<Key, Equal>(mutex_data_[way], {.hash = new_hash, .key = std::move(key)});
116116
}
117117

118118
template <typename Key, typename Equal>

core/include/userver/middlewares/runner.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ RunnerComponentBase<MiddlewareBase, HandlerInfo>::RunnerComponentBase(
172172
for (const auto& mid : names) {
173173
const auto* factory = context.FindComponentOptional<MiddlewareFactory>(mid);
174174
UINVARIANT(factory != nullptr, fmt::format("The middleware '{}' must exist", mid));
175-
middleware_infos_.push_back(MiddlewareInfo{factory, middlewares[mid]});
175+
middleware_infos_.push_back(MiddlewareInfo{.factory = factory, .local_config = middlewares[mid]});
176176
}
177177
}
178178

core/include/userver/rcu/rcu_map.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ typename RcuMap<K, V, RcuMapTraits>::InsertReturnType RcuMap<
313313
K,
314314
V,
315315
RcuMapTraits>::Insert(const K& key, typename RcuMap<K, V, RcuMapTraits>::ValuePtr value) {
316-
InsertReturnType result{Get(key), false};
316+
InsertReturnType result{.value = Get(key), .inserted = false};
317317
if (result.value) {
318318
return result;
319319
}
@@ -327,7 +327,7 @@ typename RcuMap<K, V, RcuMapTraits>::InsertReturnType RcuMap<
327327
K,
328328
V,
329329
RcuMapTraits>::Emplace(const K& key, Args&&... args) {
330-
InsertReturnType result{Get(key), false};
330+
InsertReturnType result{.value = Get(key), .inserted = false};
331331
if (result.value) {
332332
return result;
333333
}
@@ -342,7 +342,7 @@ typename RcuMap<K, V, RcuMapTraits>::InsertReturnType RcuMap<
342342
RcuMapTraits>::DoInsert(const K& key, typename RcuMap<K, V, RcuMapTraits>::ValuePtr value) {
343343
auto txn = rcu_.StartWrite();
344344
auto insertion_result = txn->emplace(key, std::move(value));
345-
InsertReturnType result{insertion_result.first->second, insertion_result.second};
345+
InsertReturnType result{.value = insertion_result.first->second, .inserted = insertion_result.second};
346346
if (result.inserted) {
347347
txn.Commit();
348348
}
@@ -355,7 +355,7 @@ typename RcuMap<K, V, RcuMapTraits>::InsertReturnType RcuMap<
355355
K,
356356
V,
357357
RcuMapTraits>::TryEmplace(const K& key, Args&&... args) {
358-
InsertReturnType result{Get(key), false};
358+
InsertReturnType result{.value = Get(key), .inserted = false};
359359
if (!result.value) {
360360
auto txn = rcu_.StartWrite();
361361
auto insertion_result = txn->try_emplace(key, nullptr);

core/src/cache/cache_update_trait_test.cpp

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,60 +1036,66 @@ INSTANTIATE_UTEST_SUITE_P(
10361036
TestInvalidateAsyncAtStartup,
10371037
Values(
10381038
CacheInvalidateAsyncParams{
1039-
testsuite::impl::PeriodicUpdatesMode::kEnabled,
1040-
{
1041-
InvalidateBeforeStartPeriodicUpdates{true},
1042-
InvalidateAtFirstUpdate{true},
1043-
FirstSyncUpdate{true},
1044-
},
1045-
{1, 2, 3},
1039+
.periodic_updates_mode = testsuite::impl::PeriodicUpdatesMode::kEnabled,
1040+
.settings =
1041+
{
1042+
.invalidate_before_start_periodic_updates = InvalidateBeforeStartPeriodicUpdates{true},
1043+
.invalidate_at_first_update = InvalidateAtFirstUpdate{true},
1044+
.first_sync_update = FirstSyncUpdate{true},
1045+
},
1046+
.expected_updates_counts = {.initial_sync = 1, .initial_async = 2, .after_full_invalidation = 3},
10461047
},
10471048
CacheInvalidateAsyncParams{
1048-
testsuite::impl::PeriodicUpdatesMode::kEnabled,
1049-
{
1050-
InvalidateBeforeStartPeriodicUpdates{false},
1051-
InvalidateAtFirstUpdate{true},
1052-
FirstSyncUpdate{true},
1053-
},
1054-
{1, 2, 3},
1049+
.periodic_updates_mode = testsuite::impl::PeriodicUpdatesMode::kEnabled,
1050+
.settings =
1051+
{
1052+
.invalidate_before_start_periodic_updates = InvalidateBeforeStartPeriodicUpdates{false},
1053+
.invalidate_at_first_update = InvalidateAtFirstUpdate{true},
1054+
.first_sync_update = FirstSyncUpdate{true},
1055+
},
1056+
.expected_updates_counts = {.initial_sync = 1, .initial_async = 2, .after_full_invalidation = 3},
10551057
},
10561058
CacheInvalidateAsyncParams{
1057-
testsuite::impl::PeriodicUpdatesMode::kEnabled,
1058-
{
1059-
InvalidateBeforeStartPeriodicUpdates{true},
1060-
InvalidateAtFirstUpdate{false},
1061-
FirstSyncUpdate{true},
1062-
},
1063-
{1, 1, 2},
1059+
.periodic_updates_mode = testsuite::impl::PeriodicUpdatesMode::kEnabled,
1060+
.settings =
1061+
{
1062+
.invalidate_before_start_periodic_updates = InvalidateBeforeStartPeriodicUpdates{true},
1063+
.invalidate_at_first_update = InvalidateAtFirstUpdate{false},
1064+
.first_sync_update = FirstSyncUpdate{true},
1065+
},
1066+
.expected_updates_counts = {.initial_sync = 1, .initial_async = 1, .after_full_invalidation = 2},
10641067
},
10651068
// With periodic updates disabled, InvalidateAsync is actually performed
10661069
// synchronously, hence initial_sync == initial_async.
10671070
CacheInvalidateAsyncParams{
1068-
testsuite::impl::PeriodicUpdatesMode::kDisabled,
1069-
{
1070-
InvalidateBeforeStartPeriodicUpdates{true},
1071-
InvalidateAtFirstUpdate{true},
1072-
FirstSyncUpdate{true},
1073-
},
1074-
{2, 2, 3},
1071+
.periodic_updates_mode = testsuite::impl::PeriodicUpdatesMode::kDisabled,
1072+
.settings =
1073+
{
1074+
.invalidate_before_start_periodic_updates = InvalidateBeforeStartPeriodicUpdates{true},
1075+
.invalidate_at_first_update = InvalidateAtFirstUpdate{true},
1076+
.first_sync_update = FirstSyncUpdate{true},
1077+
},
1078+
.expected_updates_counts = {.initial_sync = 2, .initial_async = 2, .after_full_invalidation = 3},
10751079
},
10761080
CacheInvalidateAsyncParams{
1077-
testsuite::impl::PeriodicUpdatesMode::kDisabled,
1078-
{
1079-
InvalidateBeforeStartPeriodicUpdates{false},
1080-
InvalidateAtFirstUpdate{true},
1081-
FirstSyncUpdate{true},
1082-
},
1083-
{2, 2, 3},
1081+
.periodic_updates_mode = testsuite::impl::PeriodicUpdatesMode::kDisabled,
1082+
.settings =
1083+
{
1084+
.invalidate_before_start_periodic_updates = InvalidateBeforeStartPeriodicUpdates{false},
1085+
.invalidate_at_first_update = InvalidateAtFirstUpdate{true},
1086+
.first_sync_update = FirstSyncUpdate{true},
1087+
},
1088+
.expected_updates_counts = {.initial_sync = 2, .initial_async = 2, .after_full_invalidation = 3},
10841089
},
10851090
CacheInvalidateAsyncParams{
1086-
testsuite::impl::PeriodicUpdatesMode::kDisabled,
1087-
{
1088-
InvalidateBeforeStartPeriodicUpdates{true},
1089-
InvalidateAtFirstUpdate{false},
1090-
FirstSyncUpdate{true},
1091-
},
1092-
{1, 1, 2},
1091+
.periodic_updates_mode = testsuite::impl::PeriodicUpdatesMode::kDisabled,
1092+
.settings =
1093+
{
1094+
.invalidate_before_start_periodic_updates = InvalidateBeforeStartPeriodicUpdates{true},
1095+
.invalidate_at_first_update = InvalidateAtFirstUpdate{false},
1096+
.first_sync_update = FirstSyncUpdate{true},
1097+
},
1098+
.expected_updates_counts = {.initial_sync = 1, .initial_async = 1, .after_full_invalidation = 2},
10931099
}
10941100
)
10951101
);

core/src/congestion_control/controllers/linear_config.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ USERVER_NAMESPACE_BEGIN
77
namespace congestion_control::v2 {
88

99
Config Parse(const formats::json::Value& value, formats::parse::To<Config>) {
10-
Config result;
11-
result.errors_threshold_percent = value["errors-threshold-percent"].As<double>(5.0);
12-
result.safe_delta_limit = value["deactivate-delta"].As<std::size_t>(10);
13-
result.timings_burst_threshold = value["timings-burst-times-threshold"].As<double>(5);
14-
result.min_timings = std::chrono::milliseconds(value["min-timings-ms"].As<std::size_t>(20));
15-
result.min_limit = value["min-limit"].As<std::size_t>(10);
16-
result.min_qps = value["min-qps"].As<std::size_t>(10);
17-
result.use_separate_stats = value["use-separate-stats"].As<bool>(false);
18-
return result;
10+
return {
11+
.errors_threshold_percent = value["errors-threshold-percent"].As<double>(5.0),
12+
.safe_delta_limit = value["deactivate-delta"].As<std::size_t>(10),
13+
.timings_burst_threshold = static_cast<std::size_t>(value["timings-burst-times-threshold"].As<double>(5)),
14+
.min_timings = std::chrono::milliseconds(value["min-timings-ms"].As<std::size_t>(20)),
15+
.min_limit = value["min-limit"].As<std::size_t>(10),
16+
.min_qps = value["min-qps"].As<std::size_t>(10),
17+
.use_separate_stats = value["use-separate-stats"].As<bool>(false),
18+
};
1919
}
2020

2121
} // namespace congestion_control::v2

core/src/dynamic_config/config_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ extern const dynamic_config::Key<SampleStructConfig> kSampleStructConfig;
3030
// it in hpp is not strictly necessary.
3131
SampleStructConfig Parse(const formats::json::Value& value, formats::parse::To<SampleStructConfig>) {
3232
return SampleStructConfig{
33-
/*is_foo_enabled=*/value["is_foo_enabled"].As<bool>(),
34-
/*bar_period=*/value["bar_period_ms"].As<std::chrono::milliseconds>(),
33+
.is_foo_enabled = value["is_foo_enabled"].As<bool>(),
34+
.bar_period = value["bar_period_ms"].As<std::chrono::milliseconds>(),
3535
};
3636
}
3737

@@ -60,10 +60,10 @@ struct DummyConfig final {
6060
};
6161

6262
DummyConfig Parse(const formats::json::Value& value, formats::parse::To<DummyConfig>) {
63-
return {value["foo"].As<int>(), value["bar"].As<std::string>()};
63+
return {.foo = value["foo"].As<int>(), .bar = value["bar"].As<std::string>()};
6464
}
6565

66-
const dynamic_config::Key kDummyConfig{dynamic_config::ConstantConfig{}, DummyConfig{42, "what"}};
66+
const dynamic_config::Key kDummyConfig{dynamic_config::ConstantConfig{}, DummyConfig{.foo = 42, .bar = "what"}};
6767

6868
const dynamic_config::Key kIntConfig{dynamic_config::ConstantConfig{}, 0};
6969

core/src/dynamic_config/impl/snapshot.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ ConfigId Register(std::string&& name, Factory factory, std::string&& default_doc
5151
);
5252
auto& registry = Registry();
5353
registry.push_back(VariableMetadata{
54-
/*name=*/std::move(name),
55-
/*factory=*/factory,
56-
/*default_docs_map_string=*/std::move(default_docs_map_string),
54+
.name = std::move(name),
55+
.factory = factory,
56+
.default_docs_map_string = std::move(default_docs_map_string),
5757
});
5858
return registry.size() - 1;
5959
}

core/src/engine/coro/stack_usage_monitor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,10 @@ class StackUsageMonitor::Impl final {
507507

508508
UASSERT(monitor_fd_.Get() != -1);
509509
UASSERT(stop_fd_.Get() != -1);
510-
std::array<::pollfd, 2> poll_fds{::pollfd{monitor_fd_.Get(), POLLIN, 0}, ::pollfd{stop_fd_.Get(), POLLIN, 0}};
510+
std::array<::pollfd, 2> poll_fds{
511+
::pollfd{.fd = monitor_fd_.Get(), .events = POLLIN, .revents = 0},
512+
::pollfd{.fd = stop_fd_.Get(), .events = POLLIN, .revents = 0},
513+
};
511514

512515
while (true) {
513516
poll_fds[0].revents = poll_fds[1].revents = 0;

core/src/engine/ev/watcher.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void Watcher<EvType>::StopAsync() noexcept {
185185
if (!IsActive()) {
186186
return;
187187
}
188-
PushAsyncOp({AsyncOpType::kStop, /*epoch=*/0});
188+
PushAsyncOp({.type = AsyncOpType::kStop, .epoch = 0});
189189
}
190190

191191
template <typename EvType>

0 commit comments

Comments
 (0)