aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2025-12-04 13:17:48 +1100
committerNeil <nyamatongwe@gmail.com>2025-12-04 13:17:48 +1100
commit3370ea39fa730ec22e4a2f5496729543c96cc98b (patch)
tree748af799dbc015e1ef5cd93818be9b12f0bc820f
parent2f9129b86903d5f0756217fa719d7f1d894acebf (diff)
downloadscintilla-mirror-3370ea39fa730ec22e4a2f5496729543c96cc98b.tar.gz
Feature [feature-requests:#1564]. Use vector to store FoldMaps as map is not
nothrow default constructable.
-rw-r--r--cppcheck.suppress3
-rw-r--r--src/DBCS.cxx28
-rw-r--r--src/DBCS.h3
-rw-r--r--win32/ScintillaWin.cxx12
4 files changed, 31 insertions, 15 deletions
diff --git a/cppcheck.suppress b/cppcheck.suppress
index b8483fedf..812b65277 100644
--- a/cppcheck.suppress
+++ b/cppcheck.suppress
@@ -47,6 +47,9 @@ constParameterPointer:scintilla/win32/ScintillaWin.cxx
knownConditionTrueFalse:scintilla/src/Editor.cxx
knownConditionTrueFalse:scintilla/src/EditView.cxx
+// This makes no sense
+CastIntegerToAddressAtReturn:scintilla\src\DBCS.cxx
+
// G_DEFINE_TYPE is too complex to pass to cppcheck
unknownMacro:scintilla/gtk/PlatGTK.cxx
// G_END_DECLS
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 <cstdint>
+#include <vector>
#include <array>
#include <map>
+#include <algorithm>
#include "DBCS.h"
@@ -99,21 +101,31 @@ bool IsDBCSValidSingleByte(int codePage, int ch) noexcept {
// NOLINTEND(*-magic-numbers)
-using CodePageToFoldMap = std::map<int, FoldMap>;
+namespace {
+
+struct CodePageFoldMap {
+ int codePage = 0;
+ FoldMap foldMap;
+ explicit CodePageFoldMap(int codePage_) noexcept : codePage {codePage_} {}
+};
+
+using CodePageToFoldMap = std::vector<CodePageFoldMap>;
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;
}
}
diff --git a/src/DBCS.h b/src/DBCS.h
index 2b66db261..466d70ec7 100644
--- a/src/DBCS.h
+++ b/src/DBCS.h
@@ -41,8 +41,7 @@ struct DBCSPair {
};
using FoldMap = std::array<DBCSPair, 0x8000>;
-bool DBCSHasFoldMap(int codePage);
-FoldMap *DBCSGetMutableFoldMap(int codePage);
+FoldMap *DBCSCreateFoldMap(int codePage);
const FoldMap *DBCSGetFoldMap(int codePage);
}
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index f426c8c46..5f3258a5f 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -2848,14 +2848,16 @@ void CreateFoldMap(int codePage, FoldMap *foldingMap) {
class CaseFolderDBCS : public CaseFolderTable {
// Allocate the expandable storage here so that it does not need to be reallocated
// for each call to Fold.
- const FoldMap *foldingMap;
- UINT cp;
+ const FoldMap *foldingMap = nullptr;
+ UINT cp = 0;
public:
explicit CaseFolderDBCS(UINT cp_) : cp(cp_) {
- if (!DBCSHasFoldMap(cp)) {
- CreateFoldMap(cp, DBCSGetMutableFoldMap(cp));
- }
foldingMap = DBCSGetFoldMap(cp);
+ if (!foldingMap) {
+ FoldMap *pfm = DBCSCreateFoldMap(cp);
+ CreateFoldMap(cp, pfm);
+ foldingMap = pfm;
+ }
}
size_t Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) override;
};