lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 80a031e 06/10: Expunge an intermediate variab


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 80a031e 06/10: Expunge an intermediate variable, and simplify control flow
Date: Tue, 2 Aug 2016 12:35:20 +0000 (UTC)

branch: master
commit 80a031e95ed795cf673545fffa60ed1a49cdb9b8
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Expunge an intermediate variable, and simplify control flow
---
 cache_file_reads.hpp |   29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/cache_file_reads.hpp b/cache_file_reads.hpp
index 4050d73..662ca88 100644
--- a/cache_file_reads.hpp
+++ b/cache_file_reads.hpp
@@ -71,26 +71,23 @@ class file_cache
 
         auto i = cache_.lower_bound(filename);
         if
-            (  cache_.end() != i
-            && filename     == i->first
-            && write_time   == i->second.write_time
+            (  cache_.end() == i
+            || filename     != i->first
+            || write_time   != i->second.write_time
             )
             {
-            return i->second.data;
+            // Construct before inserting because ctor might throw.
+            retrieved_type value(new T(filename));
+
+            // insert() doesn't update the value if the key is already
+            // present, so insert a dummy value and then modify it.
+            // This works for both existing and new keys.
+            i = cache_.insert(i, std::make_pair(filename, record()));
+            i->second.data = value;
+            i->second.write_time = write_time;
             }
 
-        // Construction may throw, so do it before updating the cache.
-        retrieved_type value(new T(filename));
-
-        // insert() doesn't update the value if the key is already
-        // present, so insert a dummy value and then modify it--this
-        // works for both existing and new keys.
-        i = cache_.insert(i, std::make_pair(filename, record()));
-        record& rec = i->second;
-        rec.data = value;
-        rec.write_time = write_time;
-
-        return value;
+        return i->second.data;
         }
 
   private:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]