Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Issue 1372153007: [Editing] Speed up PositionIterator::computePosition from O(n) to O(1). (Closed)

Created:
5 years, 2 months ago by yoichio
Modified:
5 years, 2 months ago
CC:
blink-reviews
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

[Editing] Speed up PositionIterator::computePosition PositionIterator::computePosition is slow if position is before a node. That is because |PositionTemplate<Strategy>::inParentBeforeNode(node)| calculates index of |node| by counting siblings, which takes O(n) time. To avoid that, this CL let PositionIterator to remember and count index within increment() because the function usually moves position to next sibling. Then, computePosition uses the index instead of inParentBeforeNode so it takes O(1) time. -- Implementation detail -- |Vector<int> m_offsetsInAnchorNode| stores indexes within each anchor node in a path from root to position. |m_depthToAnchorNode| is a current depth of anchor node. To delay initialize each index(because we may not use all index value instantly), we initialize |m_offsetsInAnchorNode| -1 and initialize if it needs in increment(). Since this implementation supposes DOM tree doesn't change in traversal, I introduce |m_domTreeVersion| to check tree is not changed. This assumption works because PositionIterator is used on stack and DOM mutaion must not happen in traversal. BUG=514193, 543779, 545170 Committed: https://crrev.com/b6d97fc86439a6a4d164ad8caf588d67d5f635e2 Cr-Commit-Position: refs/heads/master@{#355517}

Patch Set 1 #

Total comments: 20

Patch Set 2 : update #

Total comments: 33

Patch Set 3 : Update #

Total comments: 12

Patch Set 4 : Update #

Total comments: 2

Patch Set 5 : Update assert #

Unified diffs Side-by-side diffs Delta from patch set Stats (+175 lines, -4 lines) Patch
M third_party/WebKit/Source/core/editing/PositionIterator.h View 1 2 3 4 3 chunks +19 lines, -2 lines 0 comments Download
M third_party/WebKit/Source/core/editing/PositionIterator.cpp View 1 2 3 4 8 chunks +156 lines, -2 lines 0 comments Download

Messages

Total messages: 29 (7 generated)
yoichio
5 years, 2 months ago (2015-10-08 04:39:41 UTC) #2
yoichio
5 years, 2 months ago (2015-10-08 04:39:46 UTC) #3
hajimehoshi
https://codereview.chromium.org/1372153007/diff/1/third_party/WebKit/Source/core/editing/PositionIterator.cpp File third_party/WebKit/Source/core/editing/PositionIterator.cpp (right): https://codereview.chromium.org/1372153007/diff/1/third_party/WebKit/Source/core/editing/PositionIterator.cpp#newcode38 third_party/WebKit/Source/core/editing/PositionIterator.cpp:38: m_depthToAnchorNode = 0; m_depthToAnchorNode can be initialized the same ...
5 years, 2 months ago (2015-10-08 04:57:28 UTC) #4
yosin_UTC9
Rather than remembering index in container node, it is better to return |BeforeAnchor| type of ...
5 years, 2 months ago (2015-10-08 05:19:17 UTC) #5
yosin_UTC9
BTW, do we really need to use PositionIterator? It is essentially doing nextPositionOf()/previousPosition().
5 years, 2 months ago (2015-10-08 06:07:27 UTC) #6
yoichio
On 2015/10/08 05:19:17, Yosi_UTC9 wrote: > Rather than remembering index in container node, it is ...
5 years, 2 months ago (2015-10-08 07:09:46 UTC) #7
yoichio
On 2015/10/08 06:07:27, Yosi_UTC9 wrote: > BTW, do we really need to use PositionIterator? > ...
5 years, 2 months ago (2015-10-08 07:10:27 UTC) #8
yosin_UTC9
On 2015/10/08 at 07:10:27, yoichio wrote: > On 2015/10/08 06:07:27, Yosi_UTC9 wrote: > > BTW, ...
5 years, 2 months ago (2015-10-08 07:39:06 UTC) #9
yosin_UTC9
On 2015/10/08 at 07:09:46, yoichio wrote: > On 2015/10/08 05:19:17, Yosi_UTC9 wrote: > > Rather ...
5 years, 2 months ago (2015-10-08 07:42:45 UTC) #10
yoichio
> This means implementations isVisuallyEquivalentCandidateAlgorithm and localCaretRectOfPosition are > wrong. They should return same result ...
5 years, 2 months ago (2015-10-20 07:00:44 UTC) #12
yoichio
Add tkent@ as second opinion.
5 years, 2 months ago (2015-10-20 07:01:27 UTC) #14
tkent
On 2015/10/20 at 07:00:44, yoichio wrote: > This CL fixes stable-blocker and needs to be ...
5 years, 2 months ago (2015-10-20 07:07:40 UTC) #15
yoichio
Ping. https://codereview.chromium.org/1372153007/diff/1/third_party/WebKit/Source/core/editing/PositionIterator.cpp File third_party/WebKit/Source/core/editing/PositionIterator.cpp (right): https://codereview.chromium.org/1372153007/diff/1/third_party/WebKit/Source/core/editing/PositionIterator.cpp#newcode38 third_party/WebKit/Source/core/editing/PositionIterator.cpp:38: m_depthToAnchorNode = 0; On 2015/10/08 at 04:57:27, hajimehoshi ...
5 years, 2 months ago (2015-10-21 04:35:05 UTC) #17
yosin_UTC9
https://codereview.chromium.org/1372153007/diff/40001/third_party/WebKit/Source/core/editing/PositionIterator.cpp File third_party/WebKit/Source/core/editing/PositionIterator.cpp (right): https://codereview.chromium.org/1372153007/diff/40001/third_party/WebKit/Source/core/editing/PositionIterator.cpp#newcode40 third_party/WebKit/Source/core/editing/PositionIterator.cpp:40: // Each m_offsetsInAnchorNode[offset] should be index of node, should ...
5 years, 2 months ago (2015-10-21 06:01:16 UTC) #18
yoichio
https://codereview.chromium.org/1372153007/diff/40001/third_party/WebKit/Source/core/editing/PositionIterator.cpp File third_party/WebKit/Source/core/editing/PositionIterator.cpp (right): https://codereview.chromium.org/1372153007/diff/40001/third_party/WebKit/Source/core/editing/PositionIterator.cpp#newcode40 third_party/WebKit/Source/core/editing/PositionIterator.cpp:40: // Each m_offsetsInAnchorNode[offset] should be index of node, On ...
5 years, 2 months ago (2015-10-22 04:33:58 UTC) #19
yosin_UTC9
https://codereview.chromium.org/1372153007/diff/60001/third_party/WebKit/Source/core/editing/PositionIterator.cpp File third_party/WebKit/Source/core/editing/PositionIterator.cpp (right): https://codereview.chromium.org/1372153007/diff/60001/third_party/WebKit/Source/core/editing/PositionIterator.cpp#newcode71 third_party/WebKit/Source/core/editing/PositionIterator.cpp:71: ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); Let's introduce isTreeClean() or another name ...
5 years, 2 months ago (2015-10-22 05:26:09 UTC) #20
yoichio
https://codereview.chromium.org/1372153007/diff/60001/third_party/WebKit/Source/core/editing/PositionIterator.cpp File third_party/WebKit/Source/core/editing/PositionIterator.cpp (right): https://codereview.chromium.org/1372153007/diff/60001/third_party/WebKit/Source/core/editing/PositionIterator.cpp#newcode71 third_party/WebKit/Source/core/editing/PositionIterator.cpp:71: ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); On 2015/10/22 at 05:26:09, Yosi_UTC9 wrote: ...
5 years, 2 months ago (2015-10-22 06:46:08 UTC) #21
yosin_UTC9
lgtm w/ small nits https://codereview.chromium.org/1372153007/diff/80001/third_party/WebKit/Source/core/editing/PositionIterator.cpp File third_party/WebKit/Source/core/editing/PositionIterator.cpp (right): https://codereview.chromium.org/1372153007/diff/80001/third_party/WebKit/Source/core/editing/PositionIterator.cpp#newcode124 third_party/WebKit/Source/core/editing/PositionIterator.cpp:124: ASSERT(isTreeClean()); nit: We should assert ...
5 years, 2 months ago (2015-10-22 07:20:35 UTC) #23
yoichio
Thanks. https://codereview.chromium.org/1372153007/diff/80001/third_party/WebKit/Source/core/editing/PositionIterator.cpp File third_party/WebKit/Source/core/editing/PositionIterator.cpp (right): https://codereview.chromium.org/1372153007/diff/80001/third_party/WebKit/Source/core/editing/PositionIterator.cpp#newcode124 third_party/WebKit/Source/core/editing/PositionIterator.cpp:124: ASSERT(isTreeClean()); On 2015/10/22 at 07:20:35, Yosi_UTC9 wrote: > ...
5 years, 2 months ago (2015-10-22 08:02:18 UTC) #25
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1372153007/100001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1372153007/100001
5 years, 2 months ago (2015-10-22 08:02:48 UTC) #27
commit-bot: I haz the power
Committed patchset #5 (id:100001)
5 years, 2 months ago (2015-10-22 09:01:13 UTC) #28
commit-bot: I haz the power
5 years, 2 months ago (2015-10-22 09:01:56 UTC) #29
Message was sent while issue was closed.
Patchset 5 (id:??) landed as
https://crrev.com/b6d97fc86439a6a4d164ad8caf588d67d5f635e2
Cr-Commit-Position: refs/heads/master@{#355517}

Powered by Google App Engine
This is Rietveld 408576698