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

Unified Diff: Source/platform/text/SegmentedString.h

Issue 1319913002: Remove SegmentedString::m_pushedChar{1,2} optimization (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/platform/text/SegmentedString.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/text/SegmentedString.h
diff --git a/Source/platform/text/SegmentedString.h b/Source/platform/text/SegmentedString.h
index c08742a569b058c081d66e6366fbe5813c0d9c31..bdfdf2205d54476a6fc363ade0ecb073876dce35 100644
--- a/Source/platform/text/SegmentedString.h
+++ b/Source/platform/text/SegmentedString.h
@@ -81,6 +81,29 @@ public:
}
}
+ void push(UChar c)
+ {
+ if (m_is8Bit) {
+ if (m_data.string8Ptr == m_string.characters8()) {
+ m_string.insert(&c, 1, 0);
Yoav Weiss 2015/08/27 13:19:03 AFAICT this goes back to String::append which look
kouhei (in TOK) 2015/08/28 05:38:47 I replaced this codepath with prepend() call in Se
+ m_data.string8Ptr = m_string.characters8();
+ m_length = m_string.length();
+ } else {
+ --m_data.string8Ptr;
+ ASSERT(*m_data.string8Ptr == c);
+ }
+ } else {
+ if (m_data.string16Ptr == m_string.characters16()) {
+ m_string.insert(&c, 1, 0);
+ m_data.string16Ptr = m_string.characters16();
+ m_length = m_string.length();
+ } else {
+ --m_data.string16Ptr;
+ ASSERT(*m_data.string16Ptr == static_cast<LChar>(c));
+ }
+ }
+ }
+
UChar getCurrentChar8()
{
return *m_data.string8Ptr;
@@ -148,9 +171,7 @@ private:
class PLATFORM_EXPORT SegmentedString {
public:
SegmentedString()
- : m_pushedChar1(0)
- , m_pushedChar2(0)
- , m_currentChar(0)
+ : m_currentChar(0)
, m_numberOfCharactersConsumedPriorToCurrentString(0)
, m_numberOfCharactersConsumedPriorToCurrentLine(0)
, m_currentLine(0)
@@ -163,9 +184,7 @@ public:
}
SegmentedString(const String& str)
- : m_pushedChar1(0)
- , m_pushedChar2(0)
- , m_currentString(str)
+ : m_currentString(str)
, m_currentChar(0)
, m_numberOfCharactersConsumedPriorToCurrentString(0)
, m_numberOfCharactersConsumedPriorToCurrentLine(0)
@@ -188,19 +207,7 @@ public:
bool excludeLineNumbers() const { return m_currentString.excludeLineNumbers(); }
void setExcludeLineNumbers();
- void push(UChar c)
- {
- ASSERT(c);
-
- if (!m_pushedChar1) {
- m_currentChar = m_pushedChar1 = c;
- updateSlowCaseFunctionPointers();
- } else {
- ASSERT(!m_pushedChar2);
- m_pushedChar2 = m_pushedChar1;
- m_currentChar = m_pushedChar1 = c;
- }
- }
+ void push(UChar);
bool isEmpty() const { return m_empty; }
unsigned length() const;
@@ -219,7 +226,6 @@ public:
void advance()
{
if (m_fastPathFlags & Use8BitAdvance) {
- ASSERT(!m_pushedChar1);
m_currentChar = m_currentString.incrementAndGetCurrentChar8();
decrementAndCheckLength();
return;
@@ -231,8 +237,6 @@ public:
inline void advanceAndUpdateLineNumber()
{
if (m_fastPathFlags & Use8BitAdvance) {
- ASSERT(!m_pushedChar1);
-
bool haveNewLine = (m_currentChar == '\n') & !!(m_fastPathFlags & Use8BitAdvanceAndUpdateLineNumbers);
m_currentChar = m_currentString.incrementAndGetCurrentChar8();
decrementAndCheckLength();
@@ -269,7 +273,7 @@ public:
void advancePastNewlineAndUpdateLineNumber()
{
ASSERT(currentChar() == '\n');
- if (!m_pushedChar1 && m_currentString.length() > 1) {
+ if (m_currentString.length() > 1) {
int newLineFlag = m_currentString.doNotExcludeLineNumbers();
m_currentLine += newLineFlag;
if (newLineFlag)
@@ -285,16 +289,11 @@ public:
// have space for at least |count| characters.
void advance(unsigned count, UChar* consumedCharacters);
- bool escaped() const { return m_pushedChar1; }
+ bool escaped() const { return false; }
int numberOfCharactersConsumed() const
{
int numberOfPushedCharacters = 0;
- if (m_pushedChar1) {
- ++numberOfPushedCharacters;
- if (m_pushedChar2)
- ++numberOfPushedCharacters;
- }
return m_numberOfCharactersConsumedPriorToCurrentString + m_currentString.numberOfCharactersConsumed() - numberOfPushedCharacters;
}
@@ -340,7 +339,7 @@ private:
void updateAdvanceFunctionPointers()
{
- if ((m_currentString.length() > 1) && !m_pushedChar1) {
+ if (m_currentString.length() > 1) {
if (m_currentString.is8Bit()) {
m_advanceFunc = &SegmentedString::advance8;
m_fastPathFlags = Use8BitAdvance;
@@ -373,7 +372,7 @@ private:
inline LookAheadResult lookAheadInline(const String& string, TextCaseSensitivity caseSensitivity)
{
- if (!m_pushedChar1 && string.length() <= static_cast<unsigned>(m_currentString.length())) {
+ if (string.length() <= static_cast<unsigned>(m_currentString.length())) {
String currentSubstring = m_currentString.currentSubString(string.length());
if (currentSubstring.startsWith(string, caseSensitivity))
return DidMatch;
@@ -399,8 +398,6 @@ private:
bool isComposite() const { return !m_substrings.isEmpty(); }
- UChar m_pushedChar1;
- UChar m_pushedChar2;
SegmentedSubstring m_currentString;
UChar m_currentChar;
int m_numberOfCharactersConsumedPriorToCurrentString;
« no previous file with comments | « no previous file | Source/platform/text/SegmentedString.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698