5656//
5757
5858#include < iterator>
59- #include < optional>
6059#include < unordered_map>
6160#include < unordered_set>
6261
@@ -310,14 +309,13 @@ struct CodeFolding
310309
311310private:
312311 // Cache of exiting branch names, populated on demand. Only queried roots
313- // are stored. nullopt means no exiting branches; a set holds the names.
314- std::unordered_map<Expression*, std::optional<std::unordered_set<Name>>>
315- exitingBranchCache;
312+ // are stored. An empty set means no exiting branches.
313+ std::unordered_map<Expression*, std::unordered_set<Name>> exitingBranchCache;
316314
317315 bool hasExitingBranches (Expression* expr) {
318316 auto it = exitingBranchCache.find (expr);
319317 if (it != exitingBranchCache.end ()) {
320- return it->second .has_value ();
318+ return ! it->second .empty ();
321319 }
322320 return populateExitingBranchCache (expr);
323321 }
@@ -330,16 +328,14 @@ struct CodeFolding
330328 struct CachePopulator
331329 : public PostWalker<CachePopulator,
332330 UnifiedExpressionVisitor<CachePopulator>> {
333- std::unordered_map<Expression*, std::optional<std::unordered_set<Name>>>&
334- resultCache;
331+ std::unordered_map<Expression*, std::unordered_set<Name>>& resultCache;
335332 Expression* root;
336333 bool rootResult = false ;
337334 std::unordered_map<Expression*, std::unordered_set<Name>> nameSets;
338335
339- CachePopulator (std::unordered_map<
340- Expression*,
341- std::optional<std::unordered_set<Name>>>& resultCache,
342- Expression* root)
336+ CachePopulator (
337+ std::unordered_map<Expression*, std::unordered_set<Name>>& resultCache,
338+ Expression* root)
343339 : resultCache(resultCache), root(root) {}
344340
345341 static void scan (CachePopulator* self, Expression** currp) {
@@ -367,12 +363,11 @@ struct CodeFolding
367363 } else {
368364 // Child was skipped by scan() — merge its cached names.
369365 auto cacheIt = resultCache.find (child);
370- if (cacheIt != resultCache.end () && cacheIt->second ) {
366+ if (cacheIt != resultCache.end () && ! cacheIt->second . empty () ) {
371367 if (targets.empty ()) {
372- targets = * cacheIt->second ;
368+ targets = cacheIt->second ;
373369 } else {
374- targets.insert (cacheIt->second ->begin (),
375- cacheIt->second ->end ());
370+ targets.insert (cacheIt->second .begin (), cacheIt->second .end ());
376371 }
377372 }
378373 }
@@ -396,7 +391,7 @@ struct CodeFolding
396391 resultCache[curr] = std::move (it->second );
397392 rootResult = true ;
398393 } else {
399- resultCache[curr] = std:: nullopt ;
394+ resultCache[curr] = {} ;
400395 }
401396 }
402397 }
0 commit comments