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

Unified Diff: third_party/WebKit/Source/platform/fonts/shaping/CachingWordShapeIterator.h

Issue 1530833002: Refactor word segmentation in CachingWordShapeIterator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use endIndex instead of Range, and simplified further Created 5 years 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/fonts/shaping/CachingWordShapeIterator.h
diff --git a/third_party/WebKit/Source/platform/fonts/shaping/CachingWordShapeIterator.h b/third_party/WebKit/Source/platform/fonts/shaping/CachingWordShapeIterator.h
index 42ba703dbc07a75d2c60526340f590568a3f2493..a616714f32cc50e4e3e273db6d118318ee46ab13 100644
--- a/third_party/WebKit/Source/platform/fonts/shaping/CachingWordShapeIterator.h
+++ b/third_party/WebKit/Source/platform/fonts/shaping/CachingWordShapeIterator.h
@@ -100,34 +100,53 @@ private:
bool nextWord(RefPtr<ShapeResult>* wordResult)
{
- unsigned length = m_textRun.length();
- if (m_startIndex < length) {
- if (m_textRun[m_startIndex] == spaceCharacter
- || m_textRun[m_startIndex] == tabulationCharacter) {
- TextRun wordRun = m_textRun.subRun(m_startIndex, 1);
- *wordResult = shapeWord(wordRun, m_font);
- m_startIndex++;
- return *wordResult;
- }
+ return shapeToEndIndex(wordResult, nextWordEndIndex());
+ }
+
+ static bool isWordDelimiter(UChar ch)
+ {
+ return ch == spaceCharacter || ch == tabulationCharacter;
+ }
+
+ unsigned nextWordEndIndex()
+ {
+ const unsigned length = m_textRun.length();
+ if (m_startIndex >= length)
+ return 0;
+
+ if (m_startIndex + 1u == length || isWordDelimiter(m_textRun[m_startIndex]))
+ return m_startIndex + 1;
- return nextUntilCharacterOrTab(wordResult, spaceCharacter);
+ for (unsigned i = m_startIndex + 1; ; i++) {
+ if (i == length || isWordDelimiter(m_textRun[i]))
+ return i;
+ }
+ }
+
+ bool shapeToEndIndex(RefPtr<ShapeResult>* result, unsigned endIndex)
+ {
+ if (!endIndex || endIndex <= m_startIndex)
+ return false;
+
+ const unsigned length = m_textRun.length();
+ if (!m_startIndex && endIndex == length) {
+ *result = shapeWord(m_textRun, m_font);
+ } else {
+ ASSERT(endIndex <= length);
+ TextRun subRun = m_textRun.subRun(m_startIndex, endIndex - m_startIndex);
+ *result = shapeWord(subRun, m_font);
}
- return false;
+ m_startIndex = endIndex;
+ return *result;
}
- bool nextUntilCharacterOrTab(RefPtr<ShapeResult>* wordResult, UChar delimiter)
+ unsigned endIndexUntil(UChar ch)
{
unsigned length = m_textRun.length();
ASSERT(m_startIndex < length);
for (unsigned i = m_startIndex + 1; ; i++) {
- if (i == length || m_textRun[i] == delimiter
- || m_textRun[i] == tabulationCharacter) {
- TextRun wordRun = m_textRun.subRun(m_startIndex,
- i - m_startIndex);
- m_startIndex = i;
- *wordResult = shapeWord(wordRun, m_font);
- return *wordResult;
- }
+ if (i == length || m_textRun[i] == ch)
+ return i;
}
}
@@ -147,14 +166,13 @@ private:
}
}
} else if (!m_shapeByWord) {
- if (!nextUntilCharacterOrTab(wordResult, 0))
+ if (!shapeToEndIndex(wordResult, endIndexUntil(tabulationCharacter)))
return false;
} else {
if (!nextWord(wordResult))
return false;
}
- if (!*wordResult)
- return false;
+ ASSERT(*wordResult);
m_widthSoFar += (*wordResult)->width();
return true;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698