getWorker' pure hist =
    do w <- readIORef $ hw_worker $ hs_worker hist
       case w of
         Just w' -> do touchWorkerCacheEntry (hs_worker hist)
                       if pure
                        then return w'
                        else reallySnapshot w'
         Nothing ->
             do worker <- getWorker' False $ hs_parent hist
                doHistoryEntry worker (hs_entry hist)
                freezeWorker worker
                addWorkerToLRU (hs_worker hist) worker
                wc <- workerCache
                fixupWorkerCache wc
                if pure
                 then return worker
                 else reallySnapshot worker
getWorker' pure hist =
    do w <- readIORef $ hw_worker $ hs_worker hist
       case w of
         Just w' -> do touchWorkerCacheEntry (hs_worker hist)
                       if pure
                        then return w'
                        else reallySnapshot w'
         Nothing ->
             do worker <- getWorker' False $ hs_parent hist
                doHistoryEntry worker (hs_entry hist)
                freezeWorker worker
                addWorkerToLRU (hs_worker hist) worker
                wc <- workerCache
                fixupWorkerCache wc
                if pure
                 then return worker
                 else reallySnapshot worker
getWorker' pure hist =
    do w <- readIORef $ hw_worker $ hs_worker hist
       case w of
         Just w' -> do touchWorkerCacheEntry (hs_worker hist)
                       if pure
                        then return w'
                        else reallySnapshot w'
         Nothing ->
             do worker <- getWorker' False $ hs_parent hist
                doHistoryEntry worker (hs_entry hist)
                freezeWorker worker
                addWorkerToLRU (hs_worker hist) worker
                wc <- workerCache
                fixupWorkerCache wc
                if pure
                 then return worker
                 else reallySnapshot worker