Remove gmx_ana_indexmap_t::bMapStatic.
authorTeemu Murtola <teemu.murtola@gmail.com>
Wed, 28 Aug 2013 17:38:57 +0000 (20:38 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sun, 8 Sep 2013 18:48:09 +0000 (20:48 +0200)
This state can be deduced from other variables in the structure,
removing duplicate state and simplifying the code.

Change-Id: Ia0d90ca544184e2af15a321c447f688d864b1d8d

src/gromacs/selection/indexutil.cpp
src/gromacs/selection/indexutil.h
src/gromacs/selection/position.cpp

index 2506c49b18c91d3ff79e68036110d94d5f3df7c2..df6535a4fd6faa7946f17b6b338e1ac8a0eed38d 100644 (file)
@@ -1041,7 +1041,6 @@ gmx_ana_indexmap_clear(gmx_ana_indexmap_t *m)
     m->b.nalloc_index    = 0;
     m->b.nalloc_a        = 0;
     m->bStatic           = true;
-    m->bMapStatic        = true;
 }
 
 /*!
@@ -1126,8 +1125,7 @@ gmx_ana_indexmap_init(gmx_ana_indexmap_t *m, gmx_ana_index_t *g,
     m->mapb.nra = m->b.nra;
     m->mapb.a   = m->b.a;
     std::memcpy(m->mapb.index, m->b.index, (m->nr+1)*sizeof(*(m->mapb.index)));
-    m->bStatic    = true;
-    m->bMapStatic = true;
+    m->bStatic  = true;
 }
 
 /*!
@@ -1204,8 +1202,7 @@ gmx_ana_indexmap_copy(gmx_ana_indexmap_t *dest, gmx_ana_indexmap_t *src, bool bF
     std::memcpy(dest->refid,      src->refid,      dest->nr*sizeof(*dest->refid));
     std::memcpy(dest->mapid,      src->mapid,      dest->nr*sizeof(*dest->mapid));
     std::memcpy(dest->mapb.index, src->mapb.index, (dest->mapb.nr+1)*sizeof(*dest->mapb.index));
-    dest->bStatic    = src->bStatic;
-    dest->bMapStatic = src->bMapStatic;
+    dest->bStatic = src->bStatic;
 }
 
 /*! \brief
@@ -1247,24 +1244,15 @@ gmx_ana_indexmap_update(gmx_ana_indexmap_t *m, gmx_ana_index_t *g,
                         bool bMaskOnly)
 {
     int  i, j, bi, bj;
-    bool bStatic;
 
     /* Process the simple cases first */
     if (m->type == INDEX_UNKNOWN && m->b.nra == 0)
     {
         return;
     }
-    // TODO: This could also be optimized away under some bStatic conditions.
-    if (bMaskOnly)
-    {
-        set_atoms(m, m->b.nra, m->b.a);
-    }
-    else
-    {
-        set_atoms(m, g->isize, g->index);
-    }
     if (m->type == INDEX_ALL)
     {
+        set_atoms(m, g->isize, g->index);
         if (m->b.nr > 0)
         {
             m->mapb.index[1] = g->isize;
@@ -1272,8 +1260,9 @@ gmx_ana_indexmap_update(gmx_ana_indexmap_t *m, gmx_ana_index_t *g,
         return;
     }
     /* Reset the reference IDs and mapping if necessary */
-    bStatic = (g->isize == m->b.nra && m->nr == m->b.nr);
-    if (bStatic || bMaskOnly)
+    const bool bToFull  = (g->isize == m->b.nra);
+    const bool bWasFull = (m->mapb.nra == m->b.nra);
+    if (bToFull || bMaskOnly)
     {
         if (!m->bStatic)
         {
@@ -1282,7 +1271,7 @@ gmx_ana_indexmap_update(gmx_ana_indexmap_t *m, gmx_ana_index_t *g,
                 m->refid[bj] = bj;
             }
         }
-        if (!m->bMapStatic)
+        if (!bWasFull)
         {
             for (bj = 0; bj < m->b.nr; ++bj)
             {
@@ -1292,11 +1281,12 @@ gmx_ana_indexmap_update(gmx_ana_indexmap_t *m, gmx_ana_index_t *g,
             {
                 m->mapb.index[bj] = m->b.index[bj];
             }
-            m->bMapStatic = true;
         }
+        set_atoms(m, m->b.nra, m->b.a);
+        m->nr = m->mapb.nr = m->b.nr;
     }
     /* Exit immediately if the group is static */
-    if (bStatic)
+    if (bToFull)
     {
         m->bStatic = true;
         return;
@@ -1331,6 +1321,7 @@ gmx_ana_indexmap_update(gmx_ana_indexmap_t *m, gmx_ana_index_t *g,
     }
     else
     {
+        set_atoms(m, g->isize, g->index);
         for (i = j = bi = 0, bj = -1; i < g->isize; ++i)
         {
             /* Find the next atom in the block */
@@ -1355,7 +1346,6 @@ gmx_ana_indexmap_update(gmx_ana_indexmap_t *m, gmx_ana_index_t *g,
         /* Update the number of blocks */
         m->mapb.index[bi] = g->isize;
         m->nr             = bi;
-        m->bMapStatic     = false;
     }
     m->mapb.nr = m->nr;
     m->bStatic = false;
index a8d454c8a924dbb26b5488b9201073b703fa0004..52d99f6bdfdf5572eb2632cf95eab23ed2797551 100644 (file)
@@ -178,14 +178,6 @@ typedef struct gmx_ana_indexmap_t
      * actually static.
      */
     bool                bStatic;
-    /*! \brief
-     * true if the current mapping is for the whole group (internal use only).
-     *
-     * This is used internally to optimize the evaluation such that
-     * gmx_ana_indexmap_update() does not take any time if the group is
-     * actually static.
-     */
-    bool                bMapStatic;
 } gmx_ana_indexmap_t;
 
 
index e6754a447219a202f271a70e054313064cb295a0..554fefc8435568d5f29718d92a4dbc0a91acfd5b 100644 (file)
@@ -288,8 +288,7 @@ gmx_ana_pos_empty_init(gmx_ana_pos_t *pos)
     pos->m.b.index[0]    = 0;
     /* This function should only be used to construct all the possible
      * positions, so the result should always be static. */
-    pos->m.bStatic    = true;
-    pos->m.bMapStatic = true;
+    pos->m.bStatic       = true;
 }
 
 /*!
@@ -306,12 +305,11 @@ gmx_ana_pos_empty(gmx_ana_pos_t *pos)
     pos->m.mapb.nra = 0;
     /* This should not really be necessary, but do it for safety... */
     pos->m.mapb.index[0] = 0;
-    /* We set the flags to true, although really in the empty state they
-     * should be false. This makes it possible to update the flags in
+    /* We set the flag to true, although really in the empty state it
+     * should be false. This makes it possible to update the flag in
      * gmx_ana_pos_append(), and just make a simple check in
      * gmx_ana_pos_append_finish(). */
-    pos->m.bStatic    = true;
-    pos->m.bMapStatic = true;
+    pos->m.bStatic       = true;
 }
 
 /*!
@@ -413,8 +411,7 @@ gmx_ana_pos_append(gmx_ana_pos_t *dest, gmx_ana_pos_t *src, int i, int refid)
     {
         if (refid != j)
         {
-            dest->m.bStatic    = false;
-            dest->m.bMapStatic = false;
+            dest->m.bStatic = false;
         }
         dest->m.refid[j] = refid;
         /* Use the original IDs from the output structure to correctly
@@ -439,8 +436,7 @@ gmx_ana_pos_append_finish(gmx_ana_pos_t *pos)
 {
     if (pos->m.nr != pos->m.b.nr)
     {
-        pos->m.bStatic    = false;
-        pos->m.bMapStatic = false;
+        pos->m.bStatic = false;
     }
 }