]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Save 60 kB on the Lua FFI wrappers
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 24 Jan 2022 08:59:05 +0000 (09:59 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 7 Apr 2022 14:09:52 +0000 (16:09 +0200)
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.

pdns/dnsdistdist/dnsdist-lua-ffi.cc
pdns/dnsdistdist/dnsdist-lua-ffi.hh

index 420e13f9330ec6d38325a098357286221f871a85..4a61e942f7b673167f6dc068281f4d5d825fea66 100644 (file)
@@ -618,21 +618,21 @@ void dnsdist_ffi_dnsresponse_clear_records_type(dnsdist_ffi_dnsresponse_t* dr, u
   }
 }
 
-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)
index 24ebe85d0b8eacf10a791005bf353379fe1a8e29..6971d3cd77b21f61d08199a93a5c9b0d50d3a22d 100644 (file)
@@ -128,5 +128,5 @@ struct dnsdist_ffi_servers_list_t
   const ServerPolicy::NumberedServerVector& servers;
 };
 
-const std::string& getLuaFFIWrappers();
+const char* getLuaFFIWrappers();
 void setupLuaFFIPerThreadContext(LuaContext& luaCtx);