内核优化

This commit is contained in:
2026-08-10 17:25:45 +08:00
parent c677c65f0e
commit 602e73f3b3
23 changed files with 221 additions and 52 deletions
@@ -76,3 +76,38 @@ TEST(double_state_strategy_test, notifies_observer_for_cache_update_and_publish)
EXPECT_EQ(recorder.data->publish_count, 1);
EXPECT_EQ(recorder.data->value, 8);
}
struct Double_State_Throwing_Assignment_State {
int first{};
int second{};
Double_State_Throwing_Assignment_State() = default;
Double_State_Throwing_Assignment_State(int first, int second) : first(first), second(second) {}
Double_State_Throwing_Assignment_State(const Double_State_Throwing_Assignment_State&) = default;
Double_State_Throwing_Assignment_State(Double_State_Throwing_Assignment_State&&) noexcept = default;
Double_State_Throwing_Assignment_State& operator=(const Double_State_Throwing_Assignment_State& other) {
first = other.first;
if (throw_on_copy_assignment) {
throw std::runtime_error("state assignment failed");
}
second = other.second;
return *this;
}
Double_State_Throwing_Assignment_State& operator=(Double_State_Throwing_Assignment_State&&) noexcept = default;
inline static bool throw_on_copy_assignment{};
};
TEST(double_state_strategy_test, failed_publish_keeps_render_state_and_revision_unchanged) {
using Strategy = Double_State_Strategy<State_Plain_Base, Double_State_Throwing_Assignment_State>;
Double_State_Throwing_Assignment_State::throw_on_copy_assignment = false;
Strategy strategy(Double_State_Throwing_Assignment_State(1, 2));
strategy.set<&Double_State_Throwing_Assignment_State::first>(10);
strategy.set<&Double_State_Throwing_Assignment_State::second>(20);
Double_State_Throwing_Assignment_State::throw_on_copy_assignment = true;
EXPECT_THROW(strategy.publish(), std::runtime_error);
Double_State_Throwing_Assignment_State::throw_on_copy_assignment = false;
EXPECT_EQ(strategy.state_revision(), 0);
EXPECT_EQ(strategy.render_use_state().first, 1);
EXPECT_EQ(strategy.render_use_state().second, 2);
strategy.publish();
EXPECT_EQ(strategy.state_revision(), 1);
EXPECT_EQ(strategy.render_use_state().first, 10);
EXPECT_EQ(strategy.render_use_state().second, 20);
}