From d4e4b3e353004fca587429f801c0592ab3fd3b99 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Sat, 22 Jun 2024 21:10:13 +0100 Subject: [PATCH] micro efficiencies --- src/secret.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/secret.c b/src/secret.c index 88d4f48..50c625d 100644 --- a/src/secret.c +++ b/src/secret.c @@ -214,6 +214,19 @@ static void mbedtls_sha3_finish(mbedtls_sha3_context *ctx, uint8_t *output, size // secretbase - internals ------------------------------------------------------ +static inline int R_Integer(SEXP x) { + int out; + switch (TYPEOF(x)) { + case INTSXP: + case LGLSXP: + out = *(int * ) DATAPTR_RO(x); + break; + default: + out = Rf_asInteger(x); + } + return out; +} + #if !defined(MBEDTLS_CT_ASM) static void * (*const volatile secure_memset)(void *, int, size_t) = memset; #endif @@ -325,7 +338,7 @@ static SEXP secretbase_sha3_impl(const SEXP x, const SEXP bits, const SEXP conve const int offset) { const int conv = LOGICAL(convert)[0]; - const int bt = Rf_asInteger(bits); + const int bt = R_Integer(bits); mbedtls_sha3_id id; if (offset < 0) {