aboutsummaryrefslogtreecommitdiffstats
path: root/c_src/nif_helpers.h
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-04-04 18:19:57 +0200
committerLoïc Hoguin <[email protected]>2014-04-04 18:19:57 +0200
commit0633a7b6f0b1eb20043b71cc59847ca8648732f0 (patch)
tree53bf4e0b99c13bf6c74659e84e1c73f8b7f0bcec /c_src/nif_helpers.h
parentf69a283b1372cfa6667e41bac56502809ec6cc76 (diff)
downloadesdl2-0633a7b6f0b1eb20043b71cc59847ca8648732f0.tar.gz
esdl2-0633a7b6f0b1eb20043b71cc59847ca8648732f0.tar.bz2
esdl2-0633a7b6f0b1eb20043b71cc59847ca8648732f0.zip
Use enif_is_identical for comparing atoms instead of strcmp
Requires us to create more atoms at startup but makes things much simpler and potentially safer and faster.
Diffstat (limited to 'c_src/nif_helpers.h')
-rw-r--r--c_src/nif_helpers.h16
1 files changed, 3 insertions, 13 deletions
diff --git a/c_src/nif_helpers.h b/c_src/nif_helpers.h
index 915cb2e..ab61998 100644
--- a/c_src/nif_helpers.h
+++ b/c_src/nif_helpers.h
@@ -68,21 +68,16 @@
// Function generators.
-#define NIF_ATOM_TO_FLAG(a, f) if (!strcmp(buf, #a)) *flags |= f; else
+#define NIF_ATOM_TO_FLAG(a, f) if (enif_is_identical(atom_ ## a, head)) *flags |= f; else
#define NIF_LIST_TO_FLAGS_FUNCTION(f, type, flags_list) \
int f(ErlNifEnv* env, ERL_NIF_TERM list, type* flags) \
{ \
- int i; \
- char buf[MAX_ATOM_LENGTH]; \
ERL_NIF_TERM head; \
\
if (!enif_is_list(env, list)) \
return 0; \
\
while (enif_get_list_cell(env, list, &head, &list)) { \
- if (!enif_get_atom(env, head, buf, MAX_ATOM_LENGTH, ERL_NIF_LATIN1)) \
- return 0; \
- \
flags_list(NIF_ATOM_TO_FLAG) /* else */ return 0; \
} \
\
@@ -98,15 +93,10 @@
return list; \
}
-#define NIF_ATOM_TO_ENUM(a, e) if (!strcmp(buf, #a)) { *val = e; return 1; }
+#define NIF_ATOM_TO_ENUM(a, e) if (enif_is_identical(atom_ ## a, atom)) { *val = e; return 1; }
#define NIF_ATOM_TO_ENUM_FUNCTION(f, type, enum_list) \
- int f(ErlNifEnv* env, ERL_NIF_TERM a, type* val) \
+ int f(ErlNifEnv* env, ERL_NIF_TERM atom, type* val) \
{ \
- char buf[MAX_ATOM_LENGTH]; \
- \
- if (!enif_get_atom(env, a, buf, MAX_ATOM_LENGTH, ERL_NIF_LATIN1)) \
- return 0; \
- \
enum_list(NIF_ATOM_TO_ENUM) \
\
return 0; \