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,6 +50,13 @@ THE SOFTWARE.
50 # define CXXOPTS_NO_REGEX true 50 # define CXXOPTS_NO_REGEX true
51 # endif 51 # endif
52 #endif 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 #ifndef CXXOPTS_NO_REGEX 61 #ifndef CXXOPTS_NO_REGEX
55 # include <regex> 62 # include <regex>
@@ -325,11 +332,11 @@ namespace cxxopts { @@ -325,11 +332,11 @@ namespace cxxopts {
325 332
326 namespace { 333 namespace {
327 #ifdef _WIN32 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 #else 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 #endif 340 #endif
334 } // namespace 341 } // namespace
335 342
@@ -744,18 +751,22 @@ inline ArguDesc ParseArgument(const char *arg, bool &amp;matched) @@ -744,18 +751,22 @@ inline ArguDesc ParseArgument(const char *arg, bool &amp;matched)
744 #else // CXXOPTS_NO_REGEX 751 #else // CXXOPTS_NO_REGEX
745 752
746 namespace { 753 namespace {
747 - 754 +CXXOPTS_LINKONCE
748 std::basic_regex<char> integer_pattern 755 std::basic_regex<char> integer_pattern
749 ("(-)?(0x)?([0-9a-zA-Z]+)|((0x)?0)"); 756 ("(-)?(0x)?([0-9a-zA-Z]+)|((0x)?0)");
  757 +CXXOPTS_LINKONCE
750 std::basic_regex<char> truthy_pattern 758 std::basic_regex<char> truthy_pattern
751 ("(t|T)(rue)?|1"); 759 ("(t|T)(rue)?|1");
  760 +CXXOPTS_LINKONCE
752 std::basic_regex<char> falsy_pattern 761 std::basic_regex<char> falsy_pattern
753 ("(f|F)(alse)?|0"); 762 ("(f|F)(alse)?|0");
754 - 763 +CXXOPTS_LINKONCE
755 std::basic_regex<char> option_matcher 764 std::basic_regex<char> option_matcher
756 ("--([[:alnum:]][-_[:alnum:]\\.]+)(=(.*))?|-([[:alnum:]].*)"); 765 ("--([[:alnum:]][-_[:alnum:]\\.]+)(=(.*))?|-([[:alnum:]].*)");
  766 +CXXOPTS_LINKONCE
757 std::basic_regex<char> option_specifier 767 std::basic_regex<char> option_specifier
758 ("([[:alnum:]][-_[:alnum:]\\.]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*"); 768 ("([[:alnum:]][-_[:alnum:]\\.]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*");
  769 +CXXOPTS_LINKONCE
759 std::basic_regex<char> option_specifier_separator(", *"); 770 std::basic_regex<char> option_specifier_separator(", *");
760 771
761 } // namespace 772 } // namespace