Changeset 65100 in webkit
- Timestamp:
- Aug 10, 2010 4:46:54 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r65099 r65100 1 2010-08-10 Adam Barth <abarth@webkit.org> 2 3 Reviewed by Eric Seidel. 4 5 SegmentedString should keep track of how many characters it consumes 6 https://bugs.webkit.org/show_bug.cgi?id=43765 7 8 The easiest way to keep track of how many characters we've consumed 9 would be to increment a counter every time we advance, but that's too 10 slow. Instead, we keep track lazily and update our summary durning the 11 slow case of advance (which is sufficiently rare). 12 13 There's some subtly to how this works w.r.t. "unconsuming" characters 14 by pushing them back on the front of the segmented string. This isn't 15 really a "right answer" here because the notion of unconsuming input 16 isn't present in the API. This patch makes some assumptions about how 17 clients of this class use its API. In a future patch, we might want to 18 rename some of the method names to make this more explicit. 19 20 * platform/text/SegmentedString.cpp: 21 (WebCore::SegmentedString::operator=): 22 (WebCore::SegmentedString::append): 23 (WebCore::SegmentedString::prepend): 24 (WebCore::SegmentedString::advanceSubstring): 25 * platform/text/SegmentedString.h: 26 (WebCore::SegmentedSubstring::numberOfCharactersConsumed): 27 (WebCore::SegmentedString::SegmentedString): 28 (WebCore::SegmentedString::numberOfCharactersConsumed): 29 1 30 2010-08-10 Gavin Barraclough <barraclough@apple.com> 2 31 -
trunk/WebCore/platform/text/SegmentedString.cpp
r62172 r65100 53 53 m_currentChar = other.m_currentChar; 54 54 m_closed = other.m_closed; 55 m_numberOfCharactersConsumedPriorToCurrentString = other.m_numberOfCharactersConsumedPriorToCurrentString; 55 56 return *this; 56 57 } … … 100 101 if (s.m_length) { 101 102 if (!m_currentString.m_length) { 103 m_numberOfCharactersConsumedPriorToCurrentString += m_currentString.numberOfCharactersConsumed(); 102 104 m_currentString = s; 103 105 } else { … … 111 113 { 112 114 ASSERT(!escaped()); 115 // FIXME: Add this ASSERT once we've deleted the LegacyHTMLDocumentParser. 116 // ASSERT(!s.numberOfCharactersConsumed()); 113 117 if (s.m_length) { 118 // FIXME: We're assuming that the prepend were originally consumed by 119 // this SegmentedString. We're also ASSERTing that s is a fresh 120 // SegmentedSubstring. These assumptions are sufficient for our 121 // current use, but we might need to handle the more elaborate 122 // cases in the future. 123 m_numberOfCharactersConsumedPriorToCurrentString += m_currentString.numberOfCharactersConsumed(); 124 m_numberOfCharactersConsumedPriorToCurrentString -= s.m_length; 114 125 if (!m_currentString.m_length) 115 126 m_currentString = s; … … 161 172 { 162 173 if (m_composite) { 174 m_numberOfCharactersConsumedPriorToCurrentString += m_currentString.numberOfCharactersConsumed(); 163 175 m_currentString = m_substrings.takeFirst(); 176 // If we've previously consumed some characters of the non-current 177 // string, we now account for those characters as part of the current 178 // string, not as part of "prior to current string." 179 m_numberOfCharactersConsumedPriorToCurrentString -= m_currentString.numberOfCharactersConsumed(); 164 180 if (m_substrings.isEmpty()) 165 181 m_composite = false; -
trunk/WebCore/platform/text/SegmentedString.h
r65031 r65100 46 46 void setExcludeLineNumbers() { m_doNotExcludeLineNumbers = false; } 47 47 48 int numberOfCharactersConsumed() const { return m_string.length() - m_length; } 49 48 50 void appendTo(String& str) const 49 51 { … … 70 72 public: 71 73 SegmentedString() 72 : m_pushedChar1(0), m_pushedChar2(0), m_currentChar(0), m_composite(false), m_closed(false) {} 74 : m_pushedChar1(0) 75 , m_pushedChar2(0) 76 , m_currentChar(0) 77 , m_numberOfCharactersConsumedPriorToCurrentString(0) 78 , m_composite(false) 79 , m_closed(false) 80 { 81 } 82 73 83 SegmentedString(const String& str) 74 : m_pushedChar1(0), m_pushedChar2(0), m_currentString(str) 75 , m_currentChar(m_currentString.m_current), m_composite(false), m_closed(false) {} 84 : m_pushedChar1(0) 85 , m_pushedChar2(0) 86 , m_currentString(str) 87 , m_currentChar(m_currentString.m_current) 88 , m_numberOfCharactersConsumedPriorToCurrentString(0) 89 , m_composite(false) 90 , m_closed(false) 91 { 92 } 93 76 94 SegmentedString(const SegmentedString&); 77 95 … … 173 191 174 192 bool escaped() const { return m_pushedChar1; } 193 194 int numberOfCharactersConsumed() 195 { 196 // We don't currently handle the case when there are pushed character. 197 ASSERT(!m_pushedChar1); 198 return m_numberOfCharactersConsumedPriorToCurrentString + m_currentString.numberOfCharactersConsumed(); 199 } 175 200 176 201 String toString() const; … … 222 247 SegmentedSubstring m_currentString; 223 248 const UChar* m_currentChar; 249 int m_numberOfCharactersConsumedPriorToCurrentString; 224 250 Deque<SegmentedSubstring> m_substrings; 225 251 bool m_composite;
Note: See TracChangeset
for help on using the changeset viewer.