Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/iterators/TextBuffer.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/iterators/TextBuffer.cpp b/third_party/WebKit/Source/core/editing/iterators/TextBuffer.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d84b7412dae2b8f045bd8a5f7935676bb7a24d4b |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/editing/iterators/TextBuffer.cpp |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/editing/iterators/TextBuffer.h" |
| + |
| +namespace blink { |
| + |
| +TextBufferBase::TextBufferBase() |
| +{ |
| + m_buffer.resize(m_buffer.capacity()); |
| +} |
| + |
| +void TextBufferBase::pushCharacters(UChar ch, size_t length) |
| +{ |
| + if (length == 0) |
| + return; |
| + std::fill_n(pushInternal(length), length, ch); |
| +} |
| + |
| +UChar* TextBufferBase::pushInternal(size_t length) |
|
yosin_UTC9
2016/01/28 09:06:17
s/pushInternal/ensureDestination/ or another, this
|
| +{ |
| + if (m_size + length > m_buffer.capacity()) |
| + grow(m_size + length); |
| + UChar* ans = pushDestination(length); |
|
yosin_UTC9
2016/01/28 09:06:17
nit: s/pushDestination/computeDestination/ or anot
|
| + m_size += length; |
| + return ans; |
| +} |
| + |
| +void TextBufferBase::grow(size_t demand) |
| +{ |
| + size_t oldCapacity = m_buffer.capacity(); |
| + m_buffer.resize(demand); |
| + m_buffer.resize(m_buffer.capacity()); |
| + shiftData(oldCapacity); |
| +} |
| + |
| +const UChar* ForwardsTextBuffer::data() const |
| +{ |
| + return m_buffer.begin(); |
| +} |
| + |
| +UChar* ForwardsTextBuffer::pushDestination(size_t length) |
| +{ |
| + ASSERT(m_size + length <= m_buffer.capacity()); |
| + return m_buffer.begin() + m_size; |
| +} |
| + |
| +const UChar* BackwardsTextBuffer::data() const |
| +{ |
| + return m_buffer.end() - m_size; |
| +} |
| + |
| +UChar* BackwardsTextBuffer::pushDestination(size_t length) |
| +{ |
| + ASSERT(m_size + length <= m_buffer.capacity()); |
| + return m_buffer.end() - m_size - length; |
| +} |
| + |
| +void BackwardsTextBuffer::shiftData(size_t oldCapacity) |
| +{ |
| + ASSERT(oldCapacity <= m_buffer.capacity()); |
| + ASSERT(m_size <= oldCapacity); |
| + std::copy_backward(m_buffer.begin() + oldCapacity - m_size, m_buffer.begin() + oldCapacity, m_buffer.end()); |
| +} |
| + |
| +} // namespace blink |