From 66c1209a55c1cff00d87c09d4290d1fbdff07ca4 Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Wed, 12 Jul 2023 23:35:58 +0200 Subject: [PATCH] +rfc: some code refactorings --- .../scintilla/OnigurumaRegExEngine.cxx | 27 ++++++++++--------- scintilla/oniguruma/src/regenc.c | 8 +++--- src/Edit.c | 17 ++---------- src/SciCall.h | 2 +- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/scintilla/oniguruma/scintilla/OnigurumaRegExEngine.cxx b/scintilla/oniguruma/scintilla/OnigurumaRegExEngine.cxx index b1bb83273..cdcdf2c85 100644 --- a/scintilla/oniguruma/scintilla/OnigurumaRegExEngine.cxx +++ b/scintilla/oniguruma/scintilla/OnigurumaRegExEngine.cxx @@ -23,6 +23,7 @@ #include #define VC_EXTRALEAN 1 +#define NOMINMAX 1 #include #include "Geometry.h" @@ -88,7 +89,11 @@ static void SetSimpleOptions(OnigOptionType &onigOptions, EOLmode /*eolMode*/, ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_NOTBOL); ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_NOTEOL); // ---------------------------------------------------------- - + //~ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_ASCII_RANGE); + //~ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_CAPTURE_GROUP); + //~ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_NOT_BEGIN_POSITION); + // ---------------------------------------------------------- + if (rangeBegIsDocBeg) { ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_NOT_BEGIN_STRING); } else { @@ -100,10 +105,7 @@ static void SetSimpleOptions(OnigOptionType &onigOptions, EOLmode /*eolMode*/, ONIG_OPTION_ON(onigOptions, ONIG_OPTION_NOT_END_STRING); } - //~ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_ASCII_RANGE); - //~ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_CAPTURE_GROUP); - //~ONIG_OPTION_ON(onigOptions, ONIG_OPTION_NOT_BEGIN_POSITION); - + // dynamic options //switch (eolMode) { // case EOLmode::CR: @@ -296,19 +298,19 @@ Sci::Position OnigurumaRegExEngine::FindText(Document* doc, Sci::Position minPos auto const docBegPos = SciPos(0); auto const docEndPos = SciPos(doc->Length()); - EOLmode const eolMode = static_cast(doc->eolMode); bool const findForward = (minPos <= maxPos); int const increment = findForward ? 1 : -1; - // Range endpoints should not be inside DBCS characters, but just in case, move them. minPos = doc->MovePositionOutsideChar(minPos, increment, true); - maxPos = doc->MovePositionOutsideChar(maxPos, increment, true); + maxPos = doc->MovePositionOutsideChar(maxPos, -increment, true); Sci::Position const rangeBeg = (findForward) ? minPos : maxPos; Sci::Position const rangeEnd = (findForward) ? maxPos : minPos; Sci::Position const rangeLen = (rangeEnd - rangeBeg); + EOLmode const eolMode = static_cast(doc->eolMode); + OnigOptionType onigOptions; SetSimpleOptions(onigOptions, eolMode, caseSensitive, findForward, searchFlags, (rangeBeg == docBegPos), (rangeEnd == docEndPos)); @@ -353,8 +355,8 @@ Sci::Position OnigurumaRegExEngine::FindText(Document* doc, Sci::Position minPos // --- search document range for pattern match --- // !!! Performance issue: Scintilla: moving Gap needs memcopy - high costs for find/replace in large document - auto const docBegPtr = UCharCPtr(doc->RangePointer(0, docEndPos)); - auto const docEndPtr = UCharCPtr(doc->RangePointer(docEndPos, 0)); + auto const docBegPtr = UCharCPtr(doc->BufferPointer()); + auto const docEndPtr = UCharCPtr(doc->RangePointer(docEndPos, 1)); auto const rangeBegPtr = UCharCPtr(doc->RangePointer(rangeBeg, rangeLen)); auto const rangeEndPtr = UCharCPtr(doc->RangePointer(rangeEnd, 0)); @@ -377,9 +379,9 @@ Sci::Position OnigurumaRegExEngine::FindText(Document* doc, Sci::Position minPos return SciPos(-3); } - if ((m_Result >= 0) && (m_Region.num_regs >= 1)) + if ((m_Result >= rangeBeg) && (m_Result <= rangeEnd) && (m_Region.num_regs >= 1)) { - //~m_MatchPos = SciPos(m_Result); // + //~m_MatchPos = SciPos(m_Result); m_MatchPos = SciPos(m_Region.beg[0]); //~m_MatchLen = SciPos(m_Region.end[0] - m_Result); m_MatchLen = SciPos(m_Region.end[0]) - m_MatchPos; @@ -742,6 +744,7 @@ public: onig_initialize(s_UsedEncodingsTypes, _ARRAYSIZE(s_UsedEncodingsTypes)); m_OnigSyntax.op |= ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END; // xcluded from ONIG_SYNTAX_DEFAULT ? + onig_set_default_syntax(&m_OnigSyntax); // std is: ONIG_SYNTAX_ONIGURUMA onig_region_init(&m_Region); diff --git a/scintilla/oniguruma/src/regenc.c b/scintilla/oniguruma/src/regenc.c index 650454787..8a06d2d5c 100644 --- a/scintilla/oniguruma/src/regenc.c +++ b/scintilla/oniguruma/src/regenc.c @@ -708,8 +708,8 @@ onigenc_is_mbc_newline_0x0a(const UChar* p, const UChar* end) #endif } #ifdef USE_END_OF_FILE_AS_LINE_TERMINATOR - //if (p == end) - // return 1; + if (p == end) + return 1; #endif return 0; } @@ -725,8 +725,8 @@ onigenc_is_mbc_newline_0x0d(const UChar* p, const UChar* end) #endif } #ifdef USE_END_OF_FILE_AS_LINE_TERMINATOR - //if (p == end) - // return 1; + if (p == end) + return 1; #endif return 0; } diff --git a/src/Edit.c b/src/Edit.c index 93144bae6..b24e37575 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -5906,19 +5906,6 @@ static char* _GetReplaceString(HWND hwnd, CLPCEDITFINDREPLACE lpefr, int* iRepla // ONIG_MISMATCH #define NOT_FOUND ((DocPos)(-1LL)) -__forceinline DocPos validate_found_pos(DocPos pos, const DocPos rbeg, const DocPos rend) -{ - if (pos >= 0LL) { - if (rbeg <= rend) { // forward search - if ((pos < rbeg) || (pos > rend)) { pos = NOT_FOUND; } - } else { - if ((pos < rend) || (pos > rbeg)) { pos = NOT_FOUND; } - } - } - return pos; -} - - static DocPos _FindInTarget(LPCWSTR wchFind, int sFlags, DocPos* begin, DocPos* end, bool bForceNext, FR_UPD_MODES fMode) { @@ -5942,7 +5929,7 @@ static DocPos _FindInTarget(LPCWSTR wchFind, int sFlags, SciCall_SetSearchFlags(sFlags); SciCall_SetTargetRange(start, stop); - iPos = validate_found_pos(SciCall_SearchInTarget(len, chFind), start, stop); // not found if beyond stop + iPos = SciCall_SearchInTarget(len, chFind); #if 1 // handle next in case of zero-length-matches or invalid position (regex) ! @@ -5953,7 +5940,7 @@ static DocPos _FindInTarget(LPCWSTR wchFind, int sFlags, bool const bProceed = (bFindNext ? (newStart < stop) : (newStart > stop)) && (newStart != iPos); if (bProceed) { SciCall_SetTargetRange(newStart, stop); - iPos = validate_found_pos(SciCall_SearchInTarget(len, chFind), newStart, stop); // not found if beyond stop + iPos = SciCall_SearchInTarget(len, chFind); // not found if beyond stop } else { iPos = NOT_FOUND; // already at document begin, end or stuck => not found diff --git a/src/SciCall.h b/src/SciCall.h index d377f7095..72ef42072 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -795,7 +795,7 @@ DeclareSciCallR0(IsSelectionRectangle, SELECTIONISRECTANGLE, bool); // length of line w/o line-end chars (full use SciCall_LineLength() #define Sci_GetNetLineLength(line) (SciCall_GetLineEndPosition(line) - SciCall_PositionFromLine(line)) -//~define Sci_GetDocEndPosition() SciCall_GetTextLength() +//~#define Sci_GetDocEndPosition() SciCall_GetTextLength() #define Sci_GetDocEndPosition() SciCall_PositionAfter(SciCall_GetTextLength() - 1) #define Sci_ClampAlpha(alpha) clampi((alpha), SC_ALPHA_TRANSPARENT, SC_ALPHA_OPAQUE) //~SC_ALPHA_NOALPHA