From 64d6551e3c6608afcd5dfd5ebdf6ad9bbac0b9f5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 25 Dec 2019 16:14:57 +0100 Subject: [PATCH] replace expensive function call with macro for trivial calculation --- src/include/gnunet_common.h | 14 ++++++++++++++ src/transport/transport_api2_communication.c | 6 +++++- src/util/common_endian.c | 8 ++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 3ac186e0b..36f9eee4a 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -997,6 +997,11 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); /* ************************* endianess conversion ****************** */ +#ifdef htonbe64 + +#define GNUNET_htonll(n) htobe64 (n) + +#else /** * Convert unsigned 64-bit integer to network byte order. * @@ -1008,7 +1013,14 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); uint64_t GNUNET_htonll (uint64_t n); +#endif + +#ifdef be64toh + +#define GNUNET_ntohll(n) be64toh (n) + +#else /** * Convert unsigned 64-bit integer to host byte order. * @@ -1020,6 +1032,8 @@ GNUNET_htonll (uint64_t n); uint64_t GNUNET_ntohll (uint64_t n); +#endif + /** * Convert double to network byte order. diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c index de5b42c3f..9df9424da 100644 --- a/src/transport/transport_api2_communication.c +++ b/src/transport/transport_api2_communication.c @@ -872,7 +872,7 @@ GNUNET_TRANSPORT_communicator_receive ( { GNUNET_log ( GNUNET_ERROR_TYPE_WARNING, - "Dropping message: transprot is too slow, queue length %llu exceeded\n", + "Dropping message: transport is too slow, queue length %llu exceeded\n", ch->max_queue_length); return GNUNET_NO; } @@ -888,6 +888,10 @@ GNUNET_TRANSPORT_communicator_receive ( im->expected_address_validity = GNUNET_TIME_relative_hton (expected_addr_validity); im->sender = *sender; + // FIXME: this is expensive, would be better if we would + // re-design the API to allow us to create the envelope first, + // and then have the application fill in the body so we do + // not have to memcpy() memcpy (&im[1], msg, msize); if (NULL != cb) { diff --git a/src/util/common_endian.c b/src/util/common_endian.c index fa7d99d85..d69cc1da5 100644 --- a/src/util/common_endian.c +++ b/src/util/common_endian.c @@ -31,6 +31,7 @@ #define LOG(kind, ...) GNUNET_log_from (kind, "util-common-endian", __VA_ARGS__) +#ifndef htonbe64 uint64_t GNUNET_htonll (uint64_t n) { @@ -44,6 +45,10 @@ GNUNET_htonll (uint64_t n) } +#endif + + +#ifndef be64toh uint64_t GNUNET_ntohll (uint64_t n) { @@ -57,6 +62,9 @@ GNUNET_ntohll (uint64_t n) } +#endif + + /** * Convert double to network-byte-order. * @param d the value in network byte order -- 2.25.1