tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 5e63b05f5423767984fbaed39ae09b5b5c01df62
parent 21953f6384e82c6ad50f6eafd9adeecb47ef65af
Author: Edgar Chen <echen@mozilla.com>
Date:   Tue,  4 Nov 2025 20:44:20 +0000

Bug 1650720 - Part 2: Simplify nsPlainTextSerializer::ConvertToLinesAndOutput; r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D270277

Diffstat:
Mdom/serializers/nsPlainTextSerializer.cpp | 41+++++++++++++++--------------------------
1 file changed, 15 insertions(+), 26 deletions(-)

diff --git a/dom/serializers/nsPlainTextSerializer.cpp b/dom/serializers/nsPlainTextSerializer.cpp @@ -1496,60 +1496,53 @@ static void ReplaceVisiblyTrailingNbsps(nsAString& aString) { } void nsPlainTextSerializer::ConvertToLinesAndOutput(const nsAString& aString) { - const int32_t totLen = aString.Length(); - int32_t newline{0}; + nsAString::const_iterator iter; + aString.BeginReading(iter); + nsAString::const_iterator done_searching; + aString.EndReading(done_searching); // Put the mail quote "> " chars in, if appropriate. // Have to put it in before every line. - int32_t bol = 0; - while (bol < totLen) { - bool outputLineBreak = false; - bool spacesOnly = true; + while (iter != done_searching) { + nsAString::const_iterator bol = iter; + nsAString::const_iterator newline = done_searching; // Find one of '\n' or '\r' using iterators since nsAString // doesn't have the old FindCharInSet function. - nsAString::const_iterator iter; - aString.BeginReading(iter); - nsAString::const_iterator done_searching; - aString.EndReading(done_searching); - iter.advance(bol); - int32_t new_newline = bol; - newline = kNotFound; + bool spacesOnly = true; while (iter != done_searching) { if ('\n' == *iter || '\r' == *iter) { - newline = new_newline; + newline = iter; break; } if (' ' != *iter) { spacesOnly = false; } - ++new_newline; ++iter; } // Done searching nsAutoString stringpart; - if (newline == kNotFound) { + bool outputLineBreak = false; + if (newline == done_searching) { // No new lines. - stringpart.Assign(Substring(aString, bol, totLen - bol)); + stringpart.Assign(Substring(bol, newline)); if (!stringpart.IsEmpty()) { char16_t lastchar = stringpart.Last(); mInWhitespace = IsLineFeedCarriageReturnBlankOrTab(lastchar); } mEmptyLines = -1; - bol = totLen; } else { // There is a newline - stringpart.Assign(Substring(aString, bol, newline - bol)); + stringpart.Assign(Substring(bol, newline)); mInWhitespace = true; outputLineBreak = true; mEmptyLines = 0; - bol = newline + 1; - if ('\r' == *iter && bol < totLen && '\n' == *++iter) { + if ('\r' == *iter++ && '\n' == *iter) { // There was a CRLF in the input. This used to be illegal and // stripped by the parser. Apparently not anymore. Let's skip // over the LF. - bol++; + ++iter; } } @@ -1573,10 +1566,6 @@ void nsPlainTextSerializer::ConvertToLinesAndOutput(const nsAString& aString) { mCurrentLine.ResetContentAndIndentationHeader(); } - -#ifdef DEBUG_wrapping - printf("No wrapping: newline is %d, totLen is %d\n", newline, totLen); -#endif } /**