From 3370ea39fa730ec22e4a2f5496729543c96cc98b Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 4 Dec 2025 13:17:48 +1100 Subject: Feature [feature-requests:#1564]. Use vector to store FoldMaps as map is not nothrow default constructable. --- src/DBCS.cxx | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/DBCS.cxx') diff --git a/src/DBCS.cxx b/src/DBCS.cxx index f4aaff433..f92b7a5a9 100644 --- a/src/DBCS.cxx +++ b/src/DBCS.cxx @@ -7,8 +7,10 @@ #include +#include #include #include +#include #include "DBCS.h" @@ -99,21 +101,31 @@ bool IsDBCSValidSingleByte(int codePage, int ch) noexcept { // NOLINTEND(*-magic-numbers) -using CodePageToFoldMap = std::map; +namespace { + +struct CodePageFoldMap { + int codePage = 0; + FoldMap foldMap; + explicit CodePageFoldMap(int codePage_) noexcept : codePage {codePage_} {} +}; + +using CodePageToFoldMap = std::vector; CodePageToFoldMap cpToFoldMap; -bool DBCSHasFoldMap(int codePage) { - const CodePageToFoldMap::const_iterator it = cpToFoldMap.find(codePage); - return it != cpToFoldMap.end(); } -FoldMap *DBCSGetMutableFoldMap(int codePage) { - // Constructs if needed - return &cpToFoldMap[codePage]; +FoldMap *DBCSCreateFoldMap(int codePage) { + cpToFoldMap.emplace_back(codePage); + return &(cpToFoldMap.back().foldMap); } const FoldMap *DBCSGetFoldMap(int codePage) { - return &cpToFoldMap[codePage]; + const CodePageToFoldMap::iterator it = std::find_if(cpToFoldMap.begin(), cpToFoldMap.end(), + [codePage](const CodePageFoldMap &cpfm) -> bool {return cpfm.codePage == codePage; }); + if (it != cpToFoldMap.end()) { + return &(it->foldMap); + } + return nullptr; } } -- cgit v1.2.3