-
Notifications
You must be signed in to change notification settings - Fork 0
[perf] hit testing and scroll #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
|
|
||
| #include "CompositionViewComponentView.h" | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include <AutoDraw.h> | ||
| #include <Fabric/AbiState.h> | ||
| #include <Fabric/AbiViewProps.h> | ||
|
|
@@ -1013,15 +1015,24 @@ bool ComponentView::anyHitTestHelper( | |
| facebook::react::Tag &targetTag, | ||
| facebook::react::Point &ptContent, | ||
| facebook::react::Point &localPt) const noexcept { | ||
| if (auto index = m_children.Size()) { | ||
| do { | ||
| index--; | ||
| targetTag = winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(m_children.GetAt(index)) | ||
| ->hitTest(ptContent, localPt); | ||
| if (targetTag != -1) { | ||
| return true; | ||
| } | ||
| } while (index != 0); | ||
| auto size = m_children.Size(); | ||
| if (size == 0) { | ||
| return false; | ||
| } | ||
|
|
||
| // Collect children into a local vector to avoid repeated O(n) IVector::GetAt calls | ||
| std::vector<winrt::Microsoft::ReactNative::ComponentView> children; | ||
| children.reserve(size); | ||
| for (auto const &child : m_children) { | ||
| children.push_back(child); | ||
| } | ||
|
Comment on lines
+1023
to
+1028
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The comment says "repeated O(n) IVector::GetAt calls", implying the original loop was O(n²). In practice, WinRT |
||
|
|
||
| for (auto it = children.rbegin(); it != children.rend(); ++it) { | ||
| targetTag = winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(*it) | ||
| ->hitTest(ptContent, localPt); | ||
| if (targetTag != -1) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noexceptfunctionoperator[]is undefined behaviour whenindex >= m_childrenCache.size(). Because the method is markednoexceptyou can't use.at()here (that would callstd::terminateon OOB), so the right fix is an explicit guard. The original WinRT-iterator path would also crash on an invalid index, so the risk level is unchanged, but since this PR is already touching this method it's a good moment to add an assert: