From bf1a9344ebe5b6e7688614d20178e4db0db5158b Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Mon, 16 Oct 2017 14:40:17 +0200 Subject: [PATCH] Reduce template instantiations of std::vector The new StringMap code for luax_enumerror causes code to be generated for std::vector. By using an extern template (an old feature standardised in c++11) we can instantiate it once instead, in StringMap.cpp. --HG-- branch : minor --- CMakeLists.txt | 1 + src/common/StringMap.cpp | 25 +++++++++++++++++++++++++ src/common/StringMap.h | 6 ++++++ 3 files changed, 32 insertions(+) create mode 100644 src/common/StringMap.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e5bd4d03..1f3aaf473 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,6 +287,7 @@ set(LOVE_SRC_COMMON src/common/runtime.h src/common/Stream.cpp src/common/Stream.h + src/common/StringMap.cpp src/common/StringMap.h src/common/types.cpp src/common/types.h diff --git a/src/common/StringMap.cpp b/src/common/StringMap.cpp new file mode 100644 index 000000000..164c4a2a5 --- /dev/null +++ b/src/common/StringMap.cpp @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2006-2017 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#include "StringMap.h" + +// See the header +template class std::vector; +template decltype(std::vector().emplace_back("")) std::vector::emplace_back(const char *const&); diff --git a/src/common/StringMap.h b/src/common/StringMap.h index 522b82ad1..f43320fd7 100644 --- a/src/common/StringMap.h +++ b/src/common/StringMap.h @@ -26,6 +26,12 @@ #include #include +// As StringMap instantiates std::vector for instances that use +// getNames(), we end up with multiple copies in the object files. This +// declaration means we only emit it once (in StringMap.cpp). +extern template class std::vector; +extern template decltype(std::vector().emplace_back("")) std::vector::emplace_back(const char *const&); + namespace love {