diff --git a/meson.build b/meson.build index 49fc2227..ad02b255 100644 --- a/meson.build +++ b/meson.build @@ -62,6 +62,7 @@ conf.set('JANET_NO_PEG', not get_option('peg')) conf.set('JANET_REDUCED_OS', get_option('reduced_os')) conf.set('JANET_NO_TYPED_ARRAY', not get_option('typed_array')) conf.set('JANET_NO_INT_TYPES', not get_option('int_types')) +conf.set('JANET_NO_PRF', not get_option('prf')) conf.set('JANET_RECURSION_GUARD', get_option('recursion_guard')) conf.set('JANET_MAX_PROTO_DEPTH', get_option('max_proto_depth')) conf.set('JANET_MAX_MACRO_EXPAND', get_option('max_macro_expand')) diff --git a/meson_options.txt b/meson_options.txt index b63c8ec1..83bd25a6 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -10,6 +10,7 @@ option('assembler', type : 'boolean', value : true) option('peg', type : 'boolean', value : true) option('typed_array', type : 'boolean', value : true) option('int_types', type : 'boolean', value : true) +option('prf', type : 'boolean', value : true) option('recursion_guard', type : 'integer', min : 10, max : 8000, value : 1024) option('max_proto_depth', type : 'integer', min : 10, max : 8000, value : 200) diff --git a/src/conf/janetconf.h b/src/conf/janetconf.h index 43dbe076..bb49a8ca 100644 --- a/src/conf/janetconf.h +++ b/src/conf/janetconf.h @@ -51,6 +51,7 @@ /* #define JANET_NO_PEG */ /* #define JANET_NO_TYPED_ARRAY */ /* #define JANET_NO_INT_TYPES */ +/* #define JANET_NO_PRF */ /* #define JANET_OUT_OF_MEMORY do { printf("janet out of memory\n"); exit(1); } while (0) */ /* #define JANET_RECURSION_GUARD 1024 */ /* #define JANET_MAX_PROTO_DEPTH 200 */ diff --git a/src/core/util.c b/src/core/util.c index 5d2b92a3..636b89a0 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -94,6 +94,18 @@ const char *const janet_status_names[16] = { "alive" }; +#ifdef JANET_NO_PRF + +int32_t janet_string_calchash(const uint8_t *str, int32_t len) { + const uint8_t *end = str + len; + uint32_t hash = 5381; + while (str < end) + hash = (hash << 5) + hash + *str++; + return (int32_t) hash; +} + +#else + /* Public domain siphash implementation sourced from: @@ -202,6 +214,8 @@ int32_t janet_string_calchash(const uint8_t *str, int32_t len) { return (int32_t)hash; } +#endif + /* Computes hash of an array of values */ int32_t janet_array_calchash(const Janet *array, int32_t len) { const Janet *end = array + len; diff --git a/src/include/janet.h b/src/include/janet.h index baecc0c3..0e5931a7 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -1302,8 +1302,10 @@ JANET_API int janet_verify(JanetFuncDef *def); JANET_API JanetBuffer *janet_pretty(JanetBuffer *buffer, int depth, int flags, Janet x); /* Misc */ -JANET_API int janet_equals(Janet x, Janet y); +#ifndef JANET_NO_PRF JANET_API void janet_init_hash_key(uint8_t key[16]); +#endif +JANET_API int janet_equals(Janet x, Janet y); JANET_API int32_t janet_hash(Janet x); JANET_API int janet_compare(Janet x, Janet y); JANET_API int janet_cstrcmp(JanetString str, const char *other);