Moving the definition of the Lua FFI wrappers outside a function avoids
a copy to be constructed on the first usage of that function. Using an
array of chars instead of a string prevents a second copy from occurring
at startup.
}
}
-const std::string& getLuaFFIWrappers()
-{
- static const std::string interface =
-#include "dnsdist-lua-ffi-interface.inc"
- ;
- static const std::string code = R"FFICodeContent(
+static constexpr char s_lua_ffi_code[] = R"FFICodeContent(
local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
-)FFICodeContent" + interface + R"FFICodeContent(
+)FFICodeContent"
+#include "dnsdist-lua-ffi-interface.inc"
+R"FFICodeContent(
]]
)FFICodeContent";
- return code;
+
+const char* getLuaFFIWrappers()
+{
+ return s_lua_ffi_code;
}
void setupLuaLoadBalancingContext(LuaContext& luaCtx)
const ServerPolicy::NumberedServerVector& servers;
};
-const std::string& getLuaFFIWrappers();
+const char* getLuaFFIWrappers();
void setupLuaFFIPerThreadContext(LuaContext& luaCtx);