Skip to content

Commit

Permalink
Make globalcontext_insert_atom(_maybe_copy) an inline function
Browse files Browse the repository at this point in the history
globalcontext_insert_atom just calls
globalcontext_insert_atom_maybe_copy that calls `atom_table_ensure_atom`.

Signed-off-by: Davide Bettio <[email protected]>
  • Loading branch information
bettio committed Nov 8, 2023
1 parent 3e98bb0 commit 8a70c75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
16 changes: 0 additions & 16 deletions src/libAtomVM/globalcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,22 +384,6 @@ int globalcontext_get_registered_process(GlobalContext *glb, int atom_index)
return 0;
}

int globalcontext_insert_atom(GlobalContext *glb, AtomString atom_string)
{
long index = atom_table_ensure_atom(glb->atom_table, atom_string, AtomTableNoOpts);
if (UNLIKELY(index == ATOM_TABLE_NOT_FOUND)) {
abort();
}
return index;
}

int globalcontext_insert_atom_maybe_copy(GlobalContext *glb, AtomString atom_string, int copy)
{
long index = atom_table_ensure_atom(
glb->atom_table, atom_string, copy ? AtomTableCopyAtom : AtomTableNoOpts);
return index;
}

bool globalcontext_is_atom_index_equal_to_atom_string(GlobalContext *glb, int atom_index_a, AtomString atom_string_b)
{
AtomString atom_string_a;
Expand Down
20 changes: 14 additions & 6 deletions src/libAtomVM/globalcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,6 @@ bool globalcontext_unregister_process(GlobalContext *glb, int atom_index);
*/
void globalcontext_maybe_unregister_process_id(GlobalContext *glb, int process_id);

/**
* @brief equivalent to globalcontext_insert_atom_maybe_copy(glb, atom_string, 0);
*/
int globalcontext_insert_atom(GlobalContext *glb, AtomString atom_string);

/**
* @brief Inserts an atom into the global atoms table, making a copy of the supplied atom
* string, if copy is non-zero.
Expand All @@ -282,7 +277,20 @@ int globalcontext_insert_atom(GlobalContext *glb, AtomString atom_string);
* assumes "ownership" of the allocated memory.
* @returns newly added atom id or -1 in case of failure.
*/
int globalcontext_insert_atom_maybe_copy(GlobalContext *glb, AtomString atom_string, int copy);
static inline int globalcontext_insert_atom_maybe_copy(GlobalContext *glb, AtomString atom_string, int copy)
{
long index = atom_table_ensure_atom(
glb->atom_table, atom_string, copy ? AtomTableCopyAtom : AtomTableNoOpts);
return index;
}

/**
* @brief equivalent to globalcontext_insert_atom_maybe_copy(glb, atom_string, 0);
*/
static inline int globalcontext_insert_atom(GlobalContext *glb, AtomString atom_string)
{
return globalcontext_insert_atom_maybe_copy(glb, atom_string, 0);
}

/**
* @brief Compares an atom table index with an AtomString.
Expand Down

0 comments on commit 8a70c75

Please sign in to comment.