Shlomi Fish avatar Shlomi Fish committed 7f82160

More consting, inlining and JIT declarations.

Comments (0)

Files changed (4)

fc-solve/source/fc_pro_iface.c

 }
 
 #define MOVES_PROCESSED_GROW_BY 32
-static void moves_processed_add_new_move(fcs_moves_processed_t * moves, fcs_extended_move_t new_move)
+static GCC_INLINE void moves_processed_add_new_move(fcs_moves_processed_t * const moves, const fcs_extended_move_t new_move)
 {
     if (! ((++moves->num_moves) & (MOVES_PROCESSED_GROW_BY - 1)))
     {
 
                case FCS_MOVE_TYPE_STACK_TO_STACK:
                     {
-                        int num_cards, virt_num_cards;
-
                         src = fcs_move_get_src_stack(move);
                         dest = fcs_move_get_dest_stack(move);
-                        num_cards = fcs_move_get_num_cards_in_seq(move);
+                        int num_cards = fcs_move_get_num_cards_in_seq(move);
                         fcs_cards_column_t src_col = fcs_state_get_col(pos, src);
                         fcs_cards_column_t dest_col = fcs_state_get_col(pos, dest);
                         int src_len = fcs_col_len(src_col);
 #ifndef min
 #define min(a,b) (((a)<(b))?(a):(b))
 #endif
-                            virt_num_cards = min((virtual_stack_len[src]-src_len), num_cards);
+                            int virt_num_cards = min((virtual_stack_len[src]-src_len), num_cards);
 #undef min
                             virtual_stack_len[src] -= virt_num_cards;
                             virtual_stack_len[dest] += virt_num_cards;
 }
 
 
-int fc_solve_moves_processed_get_next_move(fcs_moves_processed_t * moves, fcs_extended_move_t * move)
-{
-    if (moves->next_move_idx == moves->num_moves)
-    {
-        return 1;
-    }
-    *move = moves->moves[moves->next_move_idx++];
-    return 0;
-}

fc-solve/source/fc_pro_iface_pos.h

     return moves->num_moves - moves->next_move_idx;
 }
 
-extern int fc_solve_moves_processed_get_next_move(fcs_moves_processed_t * moves, fcs_extended_move_t * move);
+static GCC_INLINE int fc_solve_moves_processed_get_next_move(fcs_moves_processed_t * const moves, fcs_extended_move_t * const move)
+{
+    if (moves->next_move_idx == moves->num_moves)
+    {
+        return 1;
+    }
+    *move = moves->moves[moves->next_move_idx++];
+    return 0;
+}
 
 static GCC_INLINE void fc_solve_moves_processed_free(fcs_moves_processed_t * moves)
 {

fc-solve/source/fcs_hash.c

 
 
 
-void fc_solve_hash_init(
-    fcs_meta_compact_allocator_t * meta_alloc,
-    fc_solve_hash_t * hash,
-#ifdef FCS_INLINED_HASH_COMPARISON
-    enum FCS_INLINED_HASH_DATA_TYPE hash_type
-#else
-#ifdef FCS_WITH_CONTEXT_VARIABLE
-    int (*compare_function)(const void * key1, const void * key2, void * context),
-    void * context
-#else
-    int (*compare_function)(const void * key1, const void * key2)
-#endif
-#endif
-    )
-{
-#define HASH_WANTED_SIZE 2048
-
-    hash->size = HASH_WANTED_SIZE;
-    hash->size_bitmask = HASH_WANTED_SIZE-1;
-    hash->max_num_elems_before_resize = (HASH_WANTED_SIZE << 1);
-
-    hash->num_elems = 0;
-
-    /* Allocate a table of size entries */
-    /* Initialize all the cells of the hash table to NULL, which indicate
-       that the end of each chain is right at the start. */
-    hash->entries = (fc_solve_hash_symlink_t *)calloc(
-        HASH_WANTED_SIZE, sizeof(hash->entries[0])
-        );
-
-    hash->list_of_vacant_items = NULL;
-
-#ifdef FCS_INLINED_HASH_COMPARISON
-    hash->hash_type = hash_type;
-#else
-    hash->compare_function = compare_function;
-#ifdef FCS_WITH_CONTEXT_VARIABLE
-    hash->context = context;
-#endif
-#endif
-
-    fc_solve_compact_allocator_init(&(hash->allocator), meta_alloc);
-
-    return;
-}
 
 fcs_bool_t fc_solve_hash_insert(
     fc_solve_hash_t * hash,

fc-solve/source/fcs_hash.h

 #endif
 } fc_solve_hash_t;
 
-
-extern void
-fc_solve_hash_init(
-    fcs_meta_compact_allocator_t * meta_alloc,
-    fc_solve_hash_t * hash,
+static GCC_INLINE void fc_solve_hash_init(
+    fcs_meta_compact_allocator_t * const meta_alloc,
+    fc_solve_hash_t * const hash,
 #ifdef FCS_INLINED_HASH_COMPARISON
-    enum FCS_INLINED_HASH_DATA_TYPE hash_type
+    const enum FCS_INLINED_HASH_DATA_TYPE hash_type
 #else
 #ifdef FCS_WITH_CONTEXT_VARIABLE
-    int (*compare_function)(const void * key1, const void * key2, void * context),
-    void * context
+    const int (*compare_function)(const void * key1, const void * key2, void * context),
+    void * const context
 #else
-    int (*compare_function)(const void * key1, const void * key2)
+    const int (*compare_function)(const void * key1, const void * key2)
 #endif
 #endif
-    );
+    )
+{
+#define HASH_WANTED_SIZE 2048
+
+    hash->size = HASH_WANTED_SIZE;
+    hash->size_bitmask = HASH_WANTED_SIZE-1;
+    hash->max_num_elems_before_resize = (HASH_WANTED_SIZE << 1);
+
+    hash->num_elems = 0;
+
+    /* Allocate a table of size entries */
+    /* Initialize all the cells of the hash table to NULL, which indicate
+       that the end of each chain is right at the start. */
+    hash->entries = (fc_solve_hash_symlink_t *)calloc(
+        HASH_WANTED_SIZE, sizeof(hash->entries[0])
+        );
 
+    hash->list_of_vacant_items = NULL;
+
+#ifdef FCS_INLINED_HASH_COMPARISON
+    hash->hash_type = hash_type;
+#else
+    hash->compare_function = compare_function;
+#ifdef FCS_WITH_CONTEXT_VARIABLE
+    hash->context = context;
+#endif
+#endif
+
+    fc_solve_compact_allocator_init(&(hash->allocator), meta_alloc);
+
+    return;
+}
 /*
  * Returns FALSE if the key is new and the key/val pair was inserted.
  *      - in that case *existing_key / *existing_val will be set to key
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.