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

Issue 1678803002: Introduce TextAccumulator for Progressive Extraction from Text Iterators (Closed)

Created:
4 years, 10 months ago by Xiaocheng
Modified:
4 years, 10 months ago
Reviewers:
tkent, yosin_UTC9
CC:
blink-reviews, chromium-reviews
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Introduce TextAccumulator for Progressive Extraction from Text Iterators This CL introduces |ForwardsTextAccumulator| and |BackwardsTextAccumulator| which allow progressively accumulating text from a text iterator on a large text node. It improves efficiency when we need to iteratively accumulate and examine text from a text iterator. This is part of a larger CL [1]. [1] https://codereview.chromium.org/1604783002 BUG=n/a TEST=webkit_unit_tests --gtest_filter=*TextAccumulatorTest.*

Patch Set 1 #

Patch Set 2 : #

Total comments: 15

Patch Set 3 : #

Total comments: 2

Patch Set 4 : #

Total comments: 4

Patch Set 5 : #

Patch Set 6 : Use plain accumulator #

Total comments: 2

Patch Set 7 : Revision on naming #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+62 lines, -19 lines) Patch
M third_party/WebKit/Source/core/editing/VisibleUnits.cpp View 1 2 3 4 5 6 6 chunks +33 lines, -19 lines 0 comments Download
A third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h View 1 2 3 4 5 6 1 chunk +29 lines, -0 lines 3 comments Download

Depends on Patchset:

Messages

Total messages: 18 (3 generated)
Xiaocheng
PTAL.
4 years, 10 months ago (2016-02-08 08:55:20 UTC) #4
tkent
yosin@ should be the primary reviewer. https://codereview.chromium.org/1678803002/diff/20001/third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h File third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h (right): https://codereview.chromium.org/1678803002/diff/20001/third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h#newcode14 third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h:14: template<typename Buffer> Please ...
4 years, 10 months ago (2016-02-09 00:06:31 UTC) #5
yosin_UTC9
https://codereview.chromium.org/1678803002/diff/20001/third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h File third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h (right): https://codereview.chromium.org/1678803002/diff/20001/third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h#newcode14 third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h:14: template<typename Buffer> nit: clang-format inserts a space between |template| ...
4 years, 10 months ago (2016-02-09 01:29:40 UTC) #6
Xiaocheng
Thanks for your reviews! PTAL at patch 3. https://codereview.chromium.org/1678803002/diff/20001/third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h File third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h (right): https://codereview.chromium.org/1678803002/diff/20001/third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h#newcode14 third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h:14: template<typename ...
4 years, 10 months ago (2016-02-09 03:30:13 UTC) #7
yosin_UTC9
https://codereview.chromium.org/1678803002/diff/40001/third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h File third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h (right): https://codereview.chromium.org/1678803002/diff/40001/third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h#newcode28 third_party/WebKit/Source/core/editing/iterators/TextAccumulator.h:28: void copyFromIterator(const Iterator& it) We should use push model ...
4 years, 10 months ago (2016-02-10 02:04:04 UTC) #8
Xiaocheng
PTAL at Patch 4, which has switched to the push model as suggested.
4 years, 10 months ago (2016-02-10 07:58:54 UTC) #9
yosin_UTC9
https://codereview.chromium.org/1678803002/diff/60001/third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp File third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp (right): https://codereview.chromium.org/1678803002/diff/60001/third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp#newcode450 third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp:450: void SimplifiedBackwardsTextIteratorAlgorithm<Strategy>::copyTextProgressivelyTo(BackwardsTextAccumulator* output, bool textSecurityAware) const |textSecurityAware()| should be ...
4 years, 10 months ago (2016-02-10 08:27:53 UTC) #10
Xiaocheng
https://codereview.chromium.org/1678803002/diff/60001/third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp File third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp (right): https://codereview.chromium.org/1678803002/diff/60001/third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp#newcode450 third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp:450: void SimplifiedBackwardsTextIteratorAlgorithm<Strategy>::copyTextProgressivelyTo(BackwardsTextAccumulator* output, bool textSecurityAware) const On 2016/02/10 at ...
4 years, 10 months ago (2016-02-10 08:42:13 UTC) #11
yosin_UTC9
On 2016/02/10 at 08:42:13, xiaochengh wrote: > https://codereview.chromium.org/1678803002/diff/60001/third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp > File third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp (right): > > https://codereview.chromium.org/1678803002/diff/60001/third_party/WebKit/Source/core/editing/iterators/SimplifiedBackwardsTextIterator.cpp#newcode450 ...
4 years, 10 months ago (2016-02-10 08:56:11 UTC) #12
yosin_UTC9
On 2016/02/10 at 08:56:11, Yosi_UTC9 wrote: > On 2016/02/10 at 08:42:13, xiaochengh wrote: > > ...
4 years, 10 months ago (2016-02-10 09:10:48 UTC) #13
Xiaocheng
PTAL at Patch 6. The previous discussion suggests decoupling |Accumulator| from |TextIterator|. I think we ...
4 years, 10 months ago (2016-02-12 06:17:19 UTC) #14
yosin_UTC9
https://codereview.chromium.org/1678803002/diff/100001/third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h File third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h (right): https://codereview.chromium.org/1678803002/diff/100001/third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h#newcode17 third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h:17: int getValue() const { return m_value; } In Blink ...
4 years, 10 months ago (2016-02-12 08:07:37 UTC) #15
Xiaocheng
PTAL at patch 7. https://codereview.chromium.org/1678803002/diff/100001/third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h File third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h (right): https://codereview.chromium.org/1678803002/diff/100001/third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h#newcode17 third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h:17: int getValue() const { return ...
4 years, 10 months ago (2016-02-12 08:55:48 UTC) #16
yosin_UTC9
https://codereview.chromium.org/1678803002/diff/120001/third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h File third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h (right): https://codereview.chromium.org/1678803002/diff/120001/third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h#newcode8 third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h:8: #include "core/CoreExport.h" nit: Since nothing to export, we don't ...
4 years, 10 months ago (2016-02-15 05:58:30 UTC) #17
Xiaocheng
4 years, 10 months ago (2016-02-16 02:50:34 UTC) #18
I've been struggling with how much information has to leak from the Accumulator
class. On one hand, we don't want to couple it with text iterators; On the other
hand, letting each client manually call |enlarge()| after each push doesn't seem
very good, either. Patch 7 is an experiment where the Accumulator doesn't manage
buffer at all, but it doesn't look good.

In fact, I realized that this accumulator class may not be necessary at all.
Given that |WTFVector| maintains a capacity that grows exponentially every time
a reallocation occurs, it is already doing exactly the progressive accumulation
that we want, and I'm just reinventing the wheel (for such a long time!). Each
client only needs to maintain an |int| counter as follows:

In TextBufferBase.h:

class TextBufferBase {
public:
    size_t capacity() const { return m_buffer.capacity(); }
...
};

In VisibleUnits.cpp:

static VisiblePositionTemplate<Strategy> previousBoundary(...) {
  ...
  BackwardsTextBuffer string;
  int runLength = 0;
  ...

  if (!inTextSecurityMode) {
    while (!next && runLength < it.length()) {
      runLength += it.copyTextTo(&string, runLength, string.capacity());
      next = searchFunction(string.data(), string.size(), string.size() -
suffixLength, MayHaveMoreContext, needMoreContext);
      if (next)
         break;
    }
  } else {
    string.pushCharacters('x', it.length());
    next = 0;
  }
  it.advance();
  runLength = 0();
}


On 2016/02/15 at 05:58:30, yosin wrote:
>
https://codereview.chromium.org/1678803002/diff/120001/third_party/WebKit/Sou...
> File third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h
(right):
> 
>
https://codereview.chromium.org/1678803002/diff/120001/third_party/WebKit/Sou...
> third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h:8:
#include "core/CoreExport.h"
> nit: Since nothing to export, we don't need to include "CoreExport.h"
> 
>
https://codereview.chromium.org/1678803002/diff/120001/third_party/WebKit/Sou...
> third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h:12:
class ExponentialAccumulator {
> |ExponentialAccumulator| does accumulate nothing. It is counter.
> Do you want to make this class as base class of |BackwardsTextBuffer| and
|ForwardsTextBuffer|?
> 
> Or template class?
> 
> template <typename TextBuffer>
> class ExponentialAccumulator {
>   const UChar* data() const { return m_buffer.data() }
>   int capacity() const { return m_buffer.capacity(); }
>   int size() const { return m_buffer.size(); }
> 
>   void push(TextIterator* it) {
>      int accumulated = it.copyTextTo(&m_buffer, size(), capacity());
>      m_size += accumulated;
>   }
> 
>   void enlarge() { m_buffer.enlarge(); }
> 
>   TextBuffer m_buffer;
> };
> 
> static VisiblePositionTemplate<Strategy> previousBoundary(...) {
>   ...
>   ExponentialAccumulator<BackwardsTextBuffer> accumulator;
>   ...
> 
>   if (!inTextSecurityMode) {
>     while (!next && accumulator.size() < it.length()) {
>       accumulator.push(&it);
>       next = searchFunction(accumulator.data(), accumulator.size(),
accumulaotr.size() - suffixLength, MayHaveMoreContext,   needMoreContext);
>       if (next)
>          break;
>       // |it| hold characters more than |accumulator| buffer, we enlarge
|accumulator| to hold more characters.
>       accumulator.enlarge();
>     }
>   } else {
>     accumulator.pushCharacters('x', it.length());
>     next = 0;
>   }
>   it.advance();
>   accumulator.rest();
> }
> 
>
https://codereview.chromium.org/1678803002/diff/120001/third_party/WebKit/Sou...
> third_party/WebKit/Source/core/editing/iterators/ExponentialAccumulator.h:20:
void grow(int delta) { m_size += delta; m_capacity += delta; }
> nit: enlarge() is better name?
> nit: Don't have two statements in a line.

Powered by Google App Engine
This is Rietveld 408576698