diff --git a/far/changelog b/far/changelog index 77ca24dce4..d8f0e0741d 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,10 @@ +-------------------------------------------------------------------------------- +drkns 2024-10-01 22:23:16+01:00 - build 6378 + +1. Minimize allocations in SQLite custom collations. + +2. Warnings. + -------------------------------------------------------------------------------- drkns 2024-09-27 22:42:31+01:00 - build 6377 diff --git a/far/format.cpp b/far/format.cpp index b25b7e944d..a48bf1ac81 100644 --- a/far/format.cpp +++ b/far/format.cpp @@ -48,6 +48,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. WARNING_PUSH(3) +WARNING_DISABLE_GCC("-Wdangling-reference") WARNING_DISABLE_GCC("-Wmissing-declarations") WARNING_DISABLE_CLANG("-Weverything") diff --git a/far/sqlitedb.cpp b/far/sqlitedb.cpp index 1b29152488..8f05ae3ff9 100644 --- a/far/sqlitedb.cpp +++ b/far/sqlitedb.cpp @@ -604,36 +604,66 @@ static auto view(const void* const Data, int const Size) return std::basic_string_view{ static_cast(Data), static_cast(Size) / sizeof(char_type) }; } -template +using comparer = std::strong_ordering(string_view, string_view); + +struct collation_context +{ + static inline struct cache + { + string Buffer1, Buffer2; + } + CollationCache; + + comparer* Comparer; + int Encoding; +}; + +static void context_deleter(void* Param) +{ + std::unique_ptr(static_cast(Param)); +} + static int combined_comparer(void* const Param, int const Size1, const void* const Data1, int const Size2, const void* const Data2) { - if (view(Data1, Size1) == view(Data2, Size2)) + const auto + RawView1 = view(Data1, Size1), + RawView2 = view(Data2, Size2); + + if (RawView1 == RawView2) return 0; - if (std::bit_cast(Param) == SQLITE_UTF16) + const auto Context = static_cast(Param); + + if (Context->Encoding == SQLITE_UTF16) { - return string_sort::ordering_as_int(comparer( + return string_sort::detail::ordering_as_int(Context->Comparer( view(Data1, Size1), view(Data2, Size2) )); } - // TODO: stack buffer optimisation - return string_sort::ordering_as_int(comparer( - encoding::utf8::get_chars(view(Data1, Size1)), - encoding::utf8::get_chars(view(Data2, Size2)) + encoding::utf8::get_chars(RawView1, Context->CollationCache.Buffer1); + encoding::utf8::get_chars(RawView2, Context->CollationCache.Buffer2); + + return string_sort::detail::ordering_as_int(Context->Comparer( + Context->CollationCache.Buffer1, + Context->CollationCache.Buffer2 )); } -using comparer_type = int(void*, int, const void*, int, const void*); - -static void create_combined_collation(sqlite::sqlite3* const Db, const char* const Name, comparer_type Comparer) +static void create_combined_collation(sqlite::sqlite3* const Db, const char* const Name, comparer* const Comparer) { const auto create_collation = [&](int const Encoding) { invoke(Db, [&] { - return sqlite::sqlite3_create_collation(Db, Name, Encoding, ToPtr(Encoding), Comparer) == SQLITE_OK; + auto Context = std::make_unique(Comparer, Encoding); + + if (sqlite::sqlite3_create_collation_v2(Db, Name, Encoding, Context.get(), combined_comparer, context_deleter) != SQLITE_OK) + return false; + + Context.release(); + return true; }); }; @@ -643,10 +673,10 @@ static void create_combined_collation(sqlite::sqlite3* const Db, const char* con void SQLiteDb::add_nocase_collation() const { - create_combined_collation(m_Db.get(), "nocase", combined_comparer); + create_combined_collation(m_Db.get(), "nocase", &string_sort::keyhole::compare_ordinal_icase); } void SQLiteDb::add_numeric_collation() const { - create_combined_collation(m_Db.get(), "numeric", combined_comparer); + create_combined_collation(m_Db.get(), "numeric", &string_sort::keyhole::compare_ordinal_numeric); } diff --git a/far/tinyxml.hpp b/far/tinyxml.hpp index fa7fc0fa67..764bfb36cc 100644 --- a/far/tinyxml.hpp +++ b/far/tinyxml.hpp @@ -40,6 +40,7 @@ namespace tinyxml_impl WARNING_PUSH() WARNING_DISABLE_GCC("-Wsuggest-override") +WARNING_DISABLE_GCC("-Wtype-limits") WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant") WARNING_DISABLE_CLANG("-Weverything") diff --git a/far/vbuild.m4 b/far/vbuild.m4 index da38fc666d..1abf9d1f76 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -6377 +6378