From 7304c337f8a0f02a3fd9f43a7d011f2529801736 Mon Sep 17 00:00:00 2001 From: Junhyun Shim Date: Thu, 21 Apr 2022 02:44:19 +0200 Subject: [PATCH] Aggressive inlining --- bindings/c/test/mako/future.hpp | 7 ++++--- bindings/c/test/mako/utils.hpp | 25 ++++++++----------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/bindings/c/test/mako/future.hpp b/bindings/c/test/mako/future.hpp index ba25cfbcfa..2941102498 100644 --- a/bindings/c/test/mako/future.hpp +++ b/bindings/c/test/mako/future.hpp @@ -25,6 +25,7 @@ #include #include #include "logger.hpp" +#include "macro.hpp" extern thread_local mako::Logger logr; @@ -33,7 +34,7 @@ namespace mako { enum class FutureRC { OK, RETRY, CONFLICT, ABORT }; template -FutureRC handleForOnError(fdb::Transaction tx, FutureType f, std::string_view step) { +force_inline FutureRC handleForOnError(fdb::Transaction& tx, FutureType& f, std::string_view step) { if (auto err = f.error()) { if (err.is(1020 /*not_committed*/)) { return FutureRC::CONFLICT; @@ -51,7 +52,7 @@ FutureRC handleForOnError(fdb::Transaction tx, FutureType f, std::string_view st } template -FutureRC waitAndHandleForOnError(fdb::Transaction tx, FutureType f, std::string_view step) { +force_inline FutureRC waitAndHandleForOnError(fdb::Transaction& tx, FutureType& f, std::string_view step) { assert(f); if (auto err = f.blockUntilReady()) { logr.error("'{}' found while waiting for on_error() future, step: {}", err.what(), step); @@ -62,7 +63,7 @@ FutureRC waitAndHandleForOnError(fdb::Transaction tx, FutureType f, std::string_ // wait on any non-immediate tx-related step to complete. Follow up with on_error(). template -FutureRC waitAndHandleError(fdb::Transaction tx, FutureType f, std::string_view step) { +force_inline FutureRC waitAndHandleError(fdb::Transaction& tx, FutureType& f, std::string_view step) { assert(f); auto err = fdb::Error{}; if ((err = f.blockUntilReady())) { diff --git a/bindings/c/test/mako/utils.hpp b/bindings/c/test/mako/utils.hpp index e499160e76..da166eeccc 100644 --- a/bindings/c/test/mako/utils.hpp +++ b/bindings/c/test/mako/utils.hpp @@ -55,25 +55,13 @@ force_inline int intSize(std::string_view sv) { /* random string */ template -void randomString(Char* str, int len) { +force_inline void randomString(Char* str, int len) { assert(len >= 0); for (auto i = 0; i < len; i++) { str[i] = ('!' + urand(0, 'z' - '!')); /* generate a char from '!' to 'z' */ } } -/* random numeric string */ -template -void randomNumericString(std::basic_string& str, int len) { - if constexpr (Clear) - str.clear(); - assert(len >= 0); - str.reserve(str.size() + static_cast(len)); - for (auto i = 0; i < len; i++) { - str.push_back('0' + urand(0, 9)); /* generage a char from '0' to '9' */ - } -} - /* given the total number of rows to be inserted, * the worker process index p_idx and the thread index t_idx (both 0-based), * and the total number of processes, total_p, and threads, total_t, @@ -109,12 +97,12 @@ int digits(int num); /* fill memory slice [str, str + len) as stringified, zero-padded num */ template -void numericWithFill(Char* str, int len, int num) { +force_inline void numericWithFill(Char* str, int len, int num) { static_assert(sizeof(Char) == 1); assert(num >= 0); - for (auto i = len - 1; i >= 0; i--) { + memset(str, '0', len); + for (auto i = len - 1; num > 0 && i >= 0; i--, num /= 10) { str[i] = (num % 10) + '0'; - num /= 10; } } @@ -132,7 +120,10 @@ void genKey(Char* str, std::string_view prefix, Arguments const& args, int num) } template -void prepareKeys(int op, std::basic_string& key1, std::basic_string& key2, Arguments const& args) { +force_inline void prepareKeys(int op, + std::basic_string& key1, + std::basic_string& key2, + Arguments const& args) { const auto key1_num = nextKey(args); genKey(key1.data(), KEY_PREFIX, args, key1_num); if (args.txnspec.ops[op][OP_RANGE] > 0) {