Skip to content
Snippets Groups Projects
Commit 5dbade3d authored by Adrien Béraud's avatar Adrien Béraud
Browse files

value cache: move to lambda

parent 2028d4b1
No related branches found
No related tags found
No related merge requests found
...@@ -58,8 +58,7 @@ public: ...@@ -58,8 +58,7 @@ public:
values.clear(); values.clear();
CallbackQueue ret; CallbackQueue ret;
if (not expired_values.empty() and callback) { if (not expired_values.empty() and callback) {
auto cb = callback; ret.emplace_back([expired_values = std::move(expired_values), cb = callback]{
ret.emplace_back([expired_values, cb]{
cb(expired_values, true); cb(expired_values, true);
}); });
} }
...@@ -103,24 +102,23 @@ public: ...@@ -103,24 +102,23 @@ public:
} }
CallbackQueue ret; CallbackQueue ret;
if (not expired_values.empty() and callback) { if (not expired_values.empty() and callback) {
auto cb = callback; ret.emplace_back([cb = callback, expired_values = std::move(expired_values)]{
ret.emplace_back([cb, expired_values]{ cb(expired_values, true);
if (cb) cb(expired_values, true);
}); });
} }
return ret; return ret;
} }
time_point onValues time_point onValues
(const std::vector<Sp<Value>>& values, (const std::vector<Sp<Value>>& new_values,
const std::vector<Value::Id>& refreshed_values, const std::vector<Value::Id>& refreshed_values,
const std::vector<Value::Id>& expired_values, const std::vector<Value::Id>& expired_values,
const TypeStore& types, const time_point& now) const TypeStore& types, const time_point& now)
{ {
CallbackQueue cbs; CallbackQueue cbs;
time_point ret = time_point::max(); time_point ret = time_point::max();
if (not values.empty()) if (not new_values.empty())
cbs.splice(cbs.end(), addValues(values, types, now)); cbs.splice(cbs.end(), addValues(new_values, types, now));
for (const auto& vid : refreshed_values) for (const auto& vid : refreshed_values)
refreshValue(vid, types, now); refreshValue(vid, types, now);
for (const auto& vid : expired_values) for (const auto& vid : expired_values)
...@@ -184,11 +182,10 @@ private: ...@@ -184,11 +182,10 @@ private:
v->second.expiration = now + types.getType(v->second.data->type).expiration; v->second.expiration = now + types.getType(v->second.data->type).expiration;
} }
} }
auto cb = callback;
CallbackQueue ret; CallbackQueue ret;
if (not nvals.empty()) if (callback and not nvals.empty())
ret.emplace_back([cb, nvals]{ ret.emplace_back([cb = callback, nvals = std::move(nvals)]{
if (cb) cb(nvals, false); cb(nvals, false);
}); });
return ret; return ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment