Skip to content

Move unrelated code out of TextIterator#60819

Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
colelao:eng/Move-unrelated-code-out-of-TextIterator
Mar 18, 2026
Merged

Move unrelated code out of TextIterator#60819
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
colelao:eng/Move-unrelated-code-out-of-TextIterator

Conversation

@colelao
Copy link
Contributor

@colelao colelao commented Mar 18, 2026

5f9b798

Move unrelated code out of TextIterator
https://bugs.webkit.org/show_bug.cgi?id=310147
rdar://172786702

Reviewed by Brent Fulgham and Ryosuke Niwa.

There are a lot of helper functions in TextIterator.cpp that could
be moved into it's own file.

This change also allows other clients to use some of these helper
functions.

* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/dom/FragmentDirectiveRangeFinder.cpp:
* Source/WebCore/editing/TextIterator.cpp:
(WebCore::SearchBuffer::SearchBuffer):
(WebCore::SearchBuffer::reachedBreak):
(WebCore::SearchBuffer::search):
(WebCore::foldQuoteMarkAndReplaceNoBreakSpace): Deleted.
(WebCore::foldQuoteMarks): Deleted.
(WebCore::createSearcher): Deleted.
(WebCore::searcher): Deleted.
(WebCore::lockSearcher): Deleted.
(WebCore::unlockSearcher): Deleted.
(WebCore::isKanaLetter): Deleted.
(WebCore::isSmallKanaLetter): Deleted.
(WebCore::composedVoicedSoundMark): Deleted.
(WebCore::isCombiningVoicedSoundMark): Deleted.
(WebCore::containsKanaLetters): Deleted.
(WebCore::normalizeCharacters): Deleted.
(WebCore::isNonLatin1Separator): Deleted.
(WebCore::isSeparator): Deleted.
(WebCore::SearchBuffer::~SearchBuffer): Deleted.
(WebCore::SearchBuffer::isBadMatch const): Deleted.
(WebCore::SearchBuffer::isWordEndMatch const): Deleted.
(WebCore::SearchBuffer::isWordStartMatch const): Deleted.
* Source/WebCore/editing/TextIterator.h:
* Source/WebCore/editing/TextSearchICU.cpp: Added.
(WebCore::createSearcher):
(WebCore::globalSearcher):
(WebCore::ICUSearcher::ICUSearcher):
(WebCore::ICUSearcher::~ICUSearcher):
(WebCore::ICUSearcher::lock):
(WebCore::ICUSearcher::unlock):
(WebCore::ICUSearcher::reset):
(WebCore::ICUSearcher::searcher):
(WebCore::isBadMatch):
(WebCore::isWordStartMatch):
(WebCore::isWordEndMatch):
(WebCore::normalizeCharacters):
(WebCore::foldQuoteMarkAndReplaceNoBreakSpace):
(WebCore::isSeparator):
(WebCore::containsKanaLetters):
(WebCore::foldQuoteMarks):
(WebCore::isKanaLetter):
(WebCore::isSmallKanaLetter):
(WebCore::composedVoicedSoundMark):
(WebCore::isCombiningVoicedSoundMark):
(WebCore::isNonLatin1Separator):
* Source/WebCore/editing/TextSearchICU.h: Added.
* Source/WebCore/page/text-extraction/TextExtraction.cpp:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:

Canonical link: https://commits.webkit.org/309514@main

e8045c0

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win loading 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests loading 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe loading 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@colelao colelao requested review from cdumez and rniwa as code owners March 18, 2026 00:05
@colelao colelao self-assigned this Mar 18, 2026
@colelao colelao added the HTML Editing For bugs in HTML editing support (including designMode and contentEditable). label Mar 18, 2026
@colelao colelao requested a review from brentfulgham March 18, 2026 00:06
Copy link
Contributor

@brentfulgham brentfulgham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clean-up looks nice. Please consider renaming the files (or the classname), since it's weird to have a class defined in a file with a totally different name.

r=me

@@ -138,6 +134,7 @@ class SearchBuffer {
const bool m_targetRequiresKanaWorkaround;
Vector<char16_t> m_normalizedTarget;
mutable Vector<char16_t> m_normalizedMatch;
ICUSearcher m_ICUSearcher;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always need an ICUSearcher object? Should it be lazily initialized if someone doesn't search?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the SearchBuffer directly relies on the ICUSearcher, and it is initialized in the SearchBuffer constructor.

|| (m_options.contains(FindOption::AtWordEnds) && !isWordEndMatch(matchStart, matchedLength))) {
if ((m_targetRequiresKanaWorkaround && isBadMatch(m_buffer.subspan(matchStart, matchedLength), m_normalizedTarget.span(), m_normalizedMatch))
|| (m_options.contains(FindOption::AtWordStarts) && !isWordStartMatch(m_buffer, matchStart, matchedLength, m_options))
|| (m_options.contains(FindOption::AtWordEnds) && !isWordEndMatch(m_buffer, matchStart, matchedLength, m_options))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all of these changes needed for the switch to an external TextSearchICU object? It seems like some of this is new work related to your search improvements. I think we should keep that separate from this task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think isBadMatch, isWordStartMatch, and isWordEndMatch are placed more appropriately in ICUSearcher, so these changes are needed.

lockSearcher();

SUPPRESS_FORWARD_DECL_ARG UStringSearch* searcher = WebCore::searcher();
SUPPRESS_FORWARD_DECL_ARG UStringSearch* searcher = m_ICUSearcher.searcher();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably encapsulate all uses of UStringSearch* into SearchICU interface in a follow up change.

@colelao colelao force-pushed the eng/Move-unrelated-code-out-of-TextIterator branch from 8cebce5 to c1dfe00 Compare March 18, 2026 17:14
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 18, 2026
@colelao colelao removed the merging-blocked Applied to prevent a change from being merged label Mar 18, 2026
@colelao colelao force-pushed the eng/Move-unrelated-code-out-of-TextIterator branch from c1dfe00 to e8045c0 Compare March 18, 2026 17:29
@colelao colelao added the safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks label Mar 18, 2026
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 18, 2026
@colelao colelao removed the merging-blocked Applied to prevent a change from being merged label Mar 18, 2026
@webkit-ews-buildbot webkit-ews-buildbot added merge-queue Applied to send a pull request to merge-queue and removed safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks labels Mar 18, 2026
@webkit-ews-buildbot
Copy link
Collaborator

Safe-Merge-Queue: Build #87024.

https://bugs.webkit.org/show_bug.cgi?id=310147
rdar://172786702

Reviewed by Brent Fulgham and Ryosuke Niwa.

There are a lot of helper functions in TextIterator.cpp that could
be moved into it's own file.

This change also allows other clients to use some of these helper
functions.

* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/dom/FragmentDirectiveRangeFinder.cpp:
* Source/WebCore/editing/TextIterator.cpp:
(WebCore::SearchBuffer::SearchBuffer):
(WebCore::SearchBuffer::reachedBreak):
(WebCore::SearchBuffer::search):
(WebCore::foldQuoteMarkAndReplaceNoBreakSpace): Deleted.
(WebCore::foldQuoteMarks): Deleted.
(WebCore::createSearcher): Deleted.
(WebCore::searcher): Deleted.
(WebCore::lockSearcher): Deleted.
(WebCore::unlockSearcher): Deleted.
(WebCore::isKanaLetter): Deleted.
(WebCore::isSmallKanaLetter): Deleted.
(WebCore::composedVoicedSoundMark): Deleted.
(WebCore::isCombiningVoicedSoundMark): Deleted.
(WebCore::containsKanaLetters): Deleted.
(WebCore::normalizeCharacters): Deleted.
(WebCore::isNonLatin1Separator): Deleted.
(WebCore::isSeparator): Deleted.
(WebCore::SearchBuffer::~SearchBuffer): Deleted.
(WebCore::SearchBuffer::isBadMatch const): Deleted.
(WebCore::SearchBuffer::isWordEndMatch const): Deleted.
(WebCore::SearchBuffer::isWordStartMatch const): Deleted.
* Source/WebCore/editing/TextIterator.h:
* Source/WebCore/editing/TextSearchICU.cpp: Added.
(WebCore::createSearcher):
(WebCore::globalSearcher):
(WebCore::ICUSearcher::ICUSearcher):
(WebCore::ICUSearcher::~ICUSearcher):
(WebCore::ICUSearcher::lock):
(WebCore::ICUSearcher::unlock):
(WebCore::ICUSearcher::reset):
(WebCore::ICUSearcher::searcher):
(WebCore::isBadMatch):
(WebCore::isWordStartMatch):
(WebCore::isWordEndMatch):
(WebCore::normalizeCharacters):
(WebCore::foldQuoteMarkAndReplaceNoBreakSpace):
(WebCore::isSeparator):
(WebCore::containsKanaLetters):
(WebCore::foldQuoteMarks):
(WebCore::isKanaLetter):
(WebCore::isSmallKanaLetter):
(WebCore::composedVoicedSoundMark):
(WebCore::isCombiningVoicedSoundMark):
(WebCore::isNonLatin1Separator):
* Source/WebCore/editing/TextSearchICU.h: Added.
* Source/WebCore/page/text-extraction/TextExtraction.cpp:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:

Canonical link: https://commits.webkit.org/309514@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Move-unrelated-code-out-of-TextIterator branch from e8045c0 to 5f9b798 Compare March 18, 2026 23:51
@webkit-commit-queue
Copy link
Collaborator

Committed 309514@main (5f9b798): https://commits.webkit.org/309514@main

Reviewed commits have been landed. Closing PR #60819 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 5f9b798 into WebKit:main Mar 18, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

HTML Editing For bugs in HTML editing support (including designMode and contentEditable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants