From 357f00c8edc7536a1cc98aca873649d2674b7fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 9 Aug 2026 22:09:29 -0300 Subject: [PATCH] perf: keep common text selections in inline storage - migrate TextRanges to SmallVector with capacity for two selections - preserve vector, initializer-list, and single-range construction - add coverage for inline storage, copying, and heap fallback - export UIStyle::PropertyResolution for Windows shared builds --- include/eepp/ui/doc/textrange.hpp | 8 ++++++-- include/eepp/ui/uistyle.hpp | 2 +- src/eepp/ui/doc/textrange.cpp | 8 ++++++-- src/tests/unit_tests/textdocument_tests.cpp | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/eepp/ui/doc/textrange.hpp b/include/eepp/ui/doc/textrange.hpp index 33b2610a7..03c12cc29 100644 --- a/include/eepp/ui/doc/textrange.hpp +++ b/include/eepp/ui/doc/textrange.hpp @@ -2,8 +2,10 @@ #define EE_UI_DOC_TEXTRANGE_HPP #include +#include #include #include +#include using namespace EE::Graphics; @@ -146,13 +148,15 @@ class EE_API TextRange { static TextSelectionRange convertToOffset( const StringType& text, const TextRange& range ); }; -class EE_API TextRanges : public std::vector { +class EE_API TextRanges : public SmallVector { public: TextRanges(); TextRanges( const std::vector& ranges ); - TextRanges( const TextRange& ranges ); + TextRanges( std::initializer_list ranges ); + + TextRanges( const TextRange& range ); bool isSorted() const; diff --git a/include/eepp/ui/uistyle.hpp b/include/eepp/ui/uistyle.hpp index dca3f0949..d181ad6be 100644 --- a/include/eepp/ui/uistyle.hpp +++ b/include/eepp/ui/uistyle.hpp @@ -101,7 +101,7 @@ class EE_API UIStyle : public UIState { void applyVarValues( CSS::StyleSheetProperty* style ); protected: - class PropertyResolution { + class EE_API PropertyResolution { public: PropertyResolution( const PropertyResolution& ) = delete; PropertyResolution& operator=( const PropertyResolution& ) = delete; diff --git a/src/eepp/ui/doc/textrange.cpp b/src/eepp/ui/doc/textrange.cpp index 48aa95c5d..491fdf1c6 100644 --- a/src/eepp/ui/doc/textrange.cpp +++ b/src/eepp/ui/doc/textrange.cpp @@ -254,9 +254,13 @@ Int64 TextRange::minimumDistance( const TextRange& other ) const { TextRanges::TextRanges() {} -TextRanges::TextRanges( const std::vector& ranges ) : std::vector( ranges ) {} +TextRanges::TextRanges( const std::vector& ranges ) : + SmallVector( ranges.begin(), ranges.end() ) {} -TextRanges::TextRanges( const TextRange& ranges ) : std::vector( { ranges } ) {} +TextRanges::TextRanges( std::initializer_list ranges ) : + SmallVector( ranges ) {} + +TextRanges::TextRanges( const TextRange& range ) : SmallVector( { range } ) {} bool TextRanges::isSorted() const { return mIsSorted; diff --git a/src/tests/unit_tests/textdocument_tests.cpp b/src/tests/unit_tests/textdocument_tests.cpp index f733eabce..a432a2e63 100644 --- a/src/tests/unit_tests/textdocument_tests.cpp +++ b/src/tests/unit_tests/textdocument_tests.cpp @@ -6,6 +6,24 @@ using namespace EE::UI::Doc; using namespace EE::System; +UTEST( TextRanges, keepsCommonSelectionsInline ) { + TextRanges ranges; + EXPECT_TRUE( ranges.is_small() ); + + ranges.emplace_back( TextPosition{ 0, 0 }, TextPosition{ 0, 1 } ); + ranges.emplace_back( TextPosition{ 1, 0 }, TextPosition{ 1, 1 } ); + EXPECT_EQ( 2u, ranges.size() ); + EXPECT_TRUE( ranges.is_small() ); + + TextRanges copy = ranges; + EXPECT_TRUE( ranges == copy ); + EXPECT_TRUE( copy.is_small() ); + + ranges.emplace_back( TextPosition{ 2, 0 }, TextPosition{ 2, 1 } ); + EXPECT_EQ( 3u, ranges.size() ); + EXPECT_FALSE( ranges.is_small() ); +} + UTEST( TextDocument, insertSingleLineAtDifferentPositions ) { TextDocument doc;