PUD: remove validity time cache from the wireformat library
authorFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 3 Feb 2012 18:25:49 +0000 (19:25 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 14 Feb 2012 13:32:59 +0000 (14:32 +0100)
making the wireformat library completely stateless

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/wireformat/src/wireFormat.c

index f969291..37e8e66 100644 (file)
@@ -1,27 +1,6 @@
 #include <OlsrdPudWireFormat/wireFormat.h>
 #include <OlsrdPudWireFormat/compiler.h>
 
-/* ************************************************************************
- * VALIDITY TIME CACHE
- * ************************************************************************ */
-
-static unsigned long long cachedValidityTimeMsn[16];
-
-static bool cachedValidityTimeMsnValid = false;
-
-/**
- Setup of cache of calculated most significant nibble results of the validity
- time calculation to speed up run-time calculations. This method has to be
- called once upon first use of ValidityTime functions.
- */
-static void setupCachedValidityTimeMsn(void) {
-       unsigned int msn;
-       for (msn = 0; msn < 16; msn++) {
-               cachedValidityTimeMsn[msn] = PUD_VALIDITY_TIME_FROM_OLSR(msn, 0);
-       }
-       cachedValidityTimeMsnValid = true;
-}
-
 /* ************************************************************************
  * Validity Time
  * ************************************************************************ */
@@ -42,13 +21,10 @@ void setValidityTime(uint8_t * validityTimeField,
        unsigned long long lsn = 0;
        unsigned long long upperBound;
 
-       if (!cachedValidityTimeMsnValid) {
-               setupCachedValidityTimeMsn();
-       }
-       upperBound = cachedValidityTimeMsn[msn];
+       upperBound = PUD_VALIDITY_TIME_FROM_OLSR(msn, 0);
        while ((msn < 16) && (validityTime >= upperBound)) {
                msn++;
-               upperBound = cachedValidityTimeMsn[msn];
+               upperBound = PUD_VALIDITY_TIME_FROM_OLSR(msn, 0);
        }
        msn--;