Commit f087dc8fcdcd6aabba68e671ae17ff3e975134f4

Authored by chrisps
Committed by GitHub
1 parent 2e3c6991

Code size reduction on msvc via selectany (#373)

Showing 1 changed file with 17 additions and 6 deletions
include/cxxopts.hpp
... ... @@ -50,6 +50,13 @@ THE SOFTWARE.
50 50 # define CXXOPTS_NO_REGEX true
51 51 # endif
52 52 #endif
  53 +#if defined(_MSC_VER) && !defined(__clang__)
  54 +#define CXXOPTS_LINKONCE_CONST __declspec(selectany) extern
  55 +#define CXXOPTS_LINKONCE __declspec(selectany) extern
  56 +#else
  57 +#define CXXOPTS_LINKONCE_CONST
  58 +#define CXXOPTS_LINKONCE
  59 +#endif
53 60  
54 61 #ifndef CXXOPTS_NO_REGEX
55 62 # include <regex>
... ... @@ -325,11 +332,11 @@ namespace cxxopts {
325 332  
326 333 namespace {
327 334 #ifdef _WIN32
328   -const std::string LQUOTE("\'");
329   -const std::string RQUOTE("\'");
  335 +CXXOPTS_LINKONCE_CONST std::string LQUOTE("\'");
  336 +CXXOPTS_LINKONCE_CONST std::string RQUOTE("\'");
330 337 #else
331   -const std::string LQUOTE("‘");
332   -const std::string RQUOTE("’");
  338 +CXXOPTS_LINKONCE_CONST std::string LQUOTE("‘");
  339 +CXXOPTS_LINKONCE_CONST std::string RQUOTE("’");
333 340 #endif
334 341 } // namespace
335 342  
... ... @@ -744,18 +751,22 @@ inline ArguDesc ParseArgument(const char *arg, bool &amp;matched)
744 751 #else // CXXOPTS_NO_REGEX
745 752  
746 753 namespace {
747   -
  754 +CXXOPTS_LINKONCE
748 755 std::basic_regex<char> integer_pattern
749 756 ("(-)?(0x)?([0-9a-zA-Z]+)|((0x)?0)");
  757 +CXXOPTS_LINKONCE
750 758 std::basic_regex<char> truthy_pattern
751 759 ("(t|T)(rue)?|1");
  760 +CXXOPTS_LINKONCE
752 761 std::basic_regex<char> falsy_pattern
753 762 ("(f|F)(alse)?|0");
754   -
  763 +CXXOPTS_LINKONCE
755 764 std::basic_regex<char> option_matcher
756 765 ("--([[:alnum:]][-_[:alnum:]\\.]+)(=(.*))?|-([[:alnum:]].*)");
  766 +CXXOPTS_LINKONCE
757 767 std::basic_regex<char> option_specifier
758 768 ("([[:alnum:]][-_[:alnum:]\\.]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*");
  769 +CXXOPTS_LINKONCE
759 770 std::basic_regex<char> option_specifier_separator(", *");
760 771  
761 772 } // namespace
... ...