]> git.tdb.fi Git - libs/game.git/commitdiff
Minor optimization to AccessGuard::check
authorMikko Rasa <tdb@tdb.fi>
Sun, 4 Dec 2022 20:15:26 +0000 (22:15 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 4 Dec 2022 20:20:22 +0000 (22:20 +0200)
It doesn't need to resize the vector since it can just use the default
flag.

source/game/accessguard.h

index 26bbb4e0e99b3d7bb896c6376e7e1d22f9fae827..0f7bac76ab09f964e3623a14a0a22ec97b35af8d 100644 (file)
@@ -69,7 +69,7 @@ public:
        void unblock() { get<T>() = UNBLOCKED; }
 
        template<typename T>
-       void check() { if(get<T>()!=UNBLOCKED) throw invalid_access(T::describe()); }
+       void check();
 };
 
 
@@ -97,6 +97,14 @@ template<>
 inline void AccessGuard::unblock<void>()
 { unblock_all(); }
 
+template<typename T>
+inline void AccessGuard::check()
+{
+       unsigned index = get_index<T>();
+       if((index<flags.size() ? flags[index] : default_flag) != UNBLOCKED)
+               throw invalid_access(T::describe());
+}
+
 
 template<typename T>
 inline std::string AccessGuard::Read<T>::describe()