Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 | 3 |
| 4 This library is free software; you can redistribute it and/or | 4 This library is free software; you can redistribute it and/or |
| 5 modify it under the terms of the GNU Library General Public | 5 modify it under the terms of the GNU Library General Public |
| 6 License as published by the Free Software Foundation; either | 6 License as published by the Free Software Foundation; either |
| 7 version 2 of the License, or (at your option) any later version. | 7 version 2 of the License, or (at your option) any later version. |
| 8 | 8 |
| 9 This library is distributed in the hope that it will be useful, | 9 This library is distributed in the hope that it will be useful, |
| 10 but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 m_currentLine = 0; | 50 m_currentLine = 0; |
| 51 m_substrings.clear(); | 51 m_substrings.clear(); |
| 52 m_closed = false; | 52 m_closed = false; |
| 53 m_empty = true; | 53 m_empty = true; |
| 54 m_fastPathFlags = NoFastPath; | 54 m_fastPathFlags = NoFastPath; |
| 55 m_advanceFunc = &SegmentedString::advanceEmpty; | 55 m_advanceFunc = &SegmentedString::advanceEmpty; |
| 56 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advanceEmpty; | 56 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advanceEmpty; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void SegmentedString::append(const SegmentedSubstring& s) { | 59 void SegmentedString::append(const SegmentedSubstring& s) { |
| 60 ASSERT(!m_closed); | 60 DCHECK(!m_closed); |
| 61 if (!s.length()) | 61 if (!s.length()) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 if (!m_currentString.length()) { | 64 if (!m_currentString.length()) { |
| 65 m_numberOfCharactersConsumedPriorToCurrentString += | 65 m_numberOfCharactersConsumedPriorToCurrentString += |
| 66 m_currentString.numberOfCharactersConsumed(); | 66 m_currentString.numberOfCharactersConsumed(); |
| 67 m_currentString = s; | 67 m_currentString = s; |
| 68 updateAdvanceFunctionPointers(); | 68 updateAdvanceFunctionPointers(); |
| 69 } else { | 69 } else { |
| 70 m_substrings.push_back(s); | 70 m_substrings.push_back(s); |
| 71 } | 71 } |
| 72 m_empty = false; | 72 m_empty = false; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void SegmentedString::push(UChar c) { | 75 void SegmentedString::push(UChar c) { |
| 76 ASSERT(c); | 76 DCHECK(c); |
| 77 | 77 |
| 78 // pushIfPossible attempts to rewind the pointer in the SegmentedSubstring, | 78 // pushIfPossible attempts to rewind the pointer in the SegmentedSubstring, |
| 79 // however it will fail if the SegmentedSubstring is empty, or | 79 // however it will fail if the SegmentedSubstring is empty, or |
| 80 // when we prepended some text while consuming a SegmentedSubstring by | 80 // when we prepended some text while consuming a SegmentedSubstring by |
| 81 // document.write(). | 81 // document.write(). |
| 82 if (m_currentString.pushIfPossible(c)) { | 82 if (m_currentString.pushIfPossible(c)) { |
| 83 m_currentChar = c; | 83 m_currentChar = c; |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 | 86 |
| 87 prepend(SegmentedString(String(&c, 1)), PrependType::Unconsume); | 87 prepend(SegmentedString(String(&c, 1)), PrependType::Unconsume); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void SegmentedString::prepend(const SegmentedSubstring& s, PrependType type) { | 90 void SegmentedString::prepend(const SegmentedSubstring& s, PrependType type) { |
| 91 ASSERT(!s.numberOfCharactersConsumed()); | 91 DCHECK(!s.numberOfCharactersConsumed()); |
| 92 if (!s.length()) | 92 if (!s.length()) |
| 93 return; | 93 return; |
| 94 | 94 |
| 95 // FIXME: We're also ASSERTing that s is a fresh SegmentedSubstring. | 95 // FIXME: We're also ASSERTing that s is a fresh SegmentedSubstring. |
| 96 // The assumption is sufficient for our current use, but we might | 96 // The assumption is sufficient for our current use, but we might |
| 97 // need to handle the more elaborate cases in the future. | 97 // need to handle the more elaborate cases in the future. |
| 98 m_numberOfCharactersConsumedPriorToCurrentString += | 98 m_numberOfCharactersConsumedPriorToCurrentString += |
| 99 m_currentString.numberOfCharactersConsumed(); | 99 m_currentString.numberOfCharactersConsumed(); |
| 100 if (type == PrependType::Unconsume) | 100 if (type == PrependType::Unconsume) |
| 101 m_numberOfCharactersConsumedPriorToCurrentString -= s.length(); | 101 m_numberOfCharactersConsumedPriorToCurrentString -= s.length(); |
| 102 if (!m_currentString.length()) { | 102 if (!m_currentString.length()) { |
| 103 m_currentString = s; | 103 m_currentString = s; |
| 104 updateAdvanceFunctionPointers(); | 104 updateAdvanceFunctionPointers(); |
| 105 } else { | 105 } else { |
| 106 // Shift our m_currentString into our list. | 106 // Shift our m_currentString into our list. |
| 107 m_substrings.push_front(m_currentString); | 107 m_substrings.push_front(m_currentString); |
| 108 m_currentString = s; | 108 m_currentString = s; |
| 109 updateAdvanceFunctionPointers(); | 109 updateAdvanceFunctionPointers(); |
| 110 } | 110 } |
| 111 m_empty = false; | 111 m_empty = false; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void SegmentedString::close() { | 114 void SegmentedString::close() { |
| 115 // Closing a stream twice is likely a coding mistake. | 115 // Closing a stream twice is likely a coding mistake. |
| 116 ASSERT(!m_closed); | 116 DCHECK(!m_closed); |
| 117 m_closed = true; | 117 m_closed = true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void SegmentedString::append(const SegmentedString& s) { | 120 void SegmentedString::append(const SegmentedString& s) { |
| 121 ASSERT(!m_closed); | 121 DCHECK(!m_closed); |
| 122 | 122 |
| 123 append(s.m_currentString); | 123 append(s.m_currentString); |
| 124 if (s.isComposite()) { | 124 if (s.isComposite()) { |
| 125 Deque<SegmentedSubstring>::const_iterator it = s.m_substrings.begin(); | 125 Deque<SegmentedSubstring>::const_iterator it = s.m_substrings.begin(); |
| 126 Deque<SegmentedSubstring>::const_iterator e = s.m_substrings.end(); | 126 Deque<SegmentedSubstring>::const_iterator e = s.m_substrings.end(); |
| 127 for (; it != e; ++it) | 127 for (; it != e; ++it) |
| 128 append(*it); | 128 append(*it); |
| 129 } | 129 } |
| 130 m_currentChar = | 130 m_currentChar = |
| 131 m_currentString.length() ? m_currentString.getCurrentChar() : 0; | 131 m_currentString.length() ? m_currentString.getCurrentChar() : 0; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 decrementAndCheckLength(); | 188 decrementAndCheckLength(); |
| 189 m_currentChar = m_currentString.incrementAndGetCurrentChar8(); | 189 m_currentChar = m_currentString.incrementAndGetCurrentChar8(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void SegmentedString::advance16() { | 192 void SegmentedString::advance16() { |
| 193 decrementAndCheckLength(); | 193 decrementAndCheckLength(); |
| 194 m_currentChar = m_currentString.incrementAndGetCurrentChar16(); | 194 m_currentChar = m_currentString.incrementAndGetCurrentChar16(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void SegmentedString::advanceAndUpdateLineNumber8() { | 197 void SegmentedString::advanceAndUpdateLineNumber8() { |
| 198 ASSERT(m_currentString.getCurrentChar() == m_currentChar); | 198 DCHECK_EQ(m_currentString.getCurrentChar(), m_currentChar); |
| 199 if (m_currentChar == '\n') { | 199 if (m_currentChar == '\n') { |
| 200 ++m_currentLine; | 200 ++m_currentLine; |
| 201 m_numberOfCharactersConsumedPriorToCurrentLine = | 201 m_numberOfCharactersConsumedPriorToCurrentLine = |
| 202 numberOfCharactersConsumed() + 1; | 202 numberOfCharactersConsumed() + 1; |
| 203 } | 203 } |
| 204 decrementAndCheckLength(); | 204 decrementAndCheckLength(); |
| 205 m_currentChar = m_currentString.incrementAndGetCurrentChar8(); | 205 m_currentChar = m_currentString.incrementAndGetCurrentChar8(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void SegmentedString::advanceAndUpdateLineNumber16() { | 208 void SegmentedString::advanceAndUpdateLineNumber16() { |
| 209 ASSERT(m_currentString.getCurrentChar() == m_currentChar); | 209 DCHECK_EQ(m_currentString.getCurrentChar(), m_currentChar); |
| 210 if (m_currentChar == '\n') { | 210 if (m_currentChar == '\n') { |
| 211 ++m_currentLine; | 211 ++m_currentLine; |
| 212 m_numberOfCharactersConsumedPriorToCurrentLine = | 212 m_numberOfCharactersConsumedPriorToCurrentLine = |
| 213 numberOfCharactersConsumed() + 1; | 213 numberOfCharactersConsumed() + 1; |
| 214 } | 214 } |
| 215 decrementAndCheckLength(); | 215 decrementAndCheckLength(); |
| 216 m_currentChar = m_currentString.incrementAndGetCurrentChar16(); | 216 m_currentChar = m_currentString.incrementAndGetCurrentChar16(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void SegmentedString::advanceSlowCase() { | 219 void SegmentedString::advanceSlowCase() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 m_fastPathFlags = NoFastPath; | 253 m_fastPathFlags = NoFastPath; |
| 254 m_advanceFunc = &SegmentedString::advanceEmpty; | 254 m_advanceFunc = &SegmentedString::advanceEmpty; |
| 255 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advanceEmpty; | 255 m_advanceAndUpdateLineNumberFunc = &SegmentedString::advanceEmpty; |
| 256 } | 256 } |
| 257 | 257 |
| 258 m_currentChar = | 258 m_currentChar = |
| 259 m_currentString.length() ? m_currentString.getCurrentChar() : 0; | 259 m_currentString.length() ? m_currentString.getCurrentChar() : 0; |
| 260 } | 260 } |
| 261 | 261 |
| 262 void SegmentedString::advanceEmpty() { | 262 void SegmentedString::advanceEmpty() { |
| 263 ASSERT(!m_currentString.length() && !isComposite()); | 263 DCHECK(!m_currentString.length() && !isComposite()); |
|
tkent
2017/04/09 23:07:01
Split this into two DCHECKs
Hwanseung Lee
2017/04/11 03:29:38
Done.
| |
| 264 m_currentChar = 0; | 264 m_currentChar = 0; |
| 265 } | 265 } |
| 266 | 266 |
| 267 void SegmentedString::updateSlowCaseFunctionPointers() { | 267 void SegmentedString::updateSlowCaseFunctionPointers() { |
| 268 m_fastPathFlags = NoFastPath; | 268 m_fastPathFlags = NoFastPath; |
| 269 m_advanceFunc = &SegmentedString::advanceSlowCase; | 269 m_advanceFunc = &SegmentedString::advanceSlowCase; |
| 270 m_advanceAndUpdateLineNumberFunc = | 270 m_advanceAndUpdateLineNumberFunc = |
| 271 &SegmentedString::advanceAndUpdateLineNumberSlowCase; | 271 &SegmentedString::advanceAndUpdateLineNumberSlowCase; |
| 272 } | 272 } |
| 273 | 273 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 284 void SegmentedString::setCurrentPosition(OrdinalNumber line, | 284 void SegmentedString::setCurrentPosition(OrdinalNumber line, |
| 285 OrdinalNumber columnAftreProlog, | 285 OrdinalNumber columnAftreProlog, |
| 286 int prologLength) { | 286 int prologLength) { |
| 287 m_currentLine = line.zeroBasedInt(); | 287 m_currentLine = line.zeroBasedInt(); |
| 288 m_numberOfCharactersConsumedPriorToCurrentLine = | 288 m_numberOfCharactersConsumedPriorToCurrentLine = |
| 289 numberOfCharactersConsumed() + prologLength - | 289 numberOfCharactersConsumed() + prologLength - |
| 290 columnAftreProlog.zeroBasedInt(); | 290 columnAftreProlog.zeroBasedInt(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 } // namespace blink | 293 } // namespace blink |
| OLD | NEW |