mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibWeb: Make whitespace collapsing stateless
Previously, the whitespace collapsing code had a parameter telling it whether the previous text node ended in whitespace. This was not actually necessary, so let's get rid of it.
This commit is contained in:
parent
66582a875f
commit
4575ab558b
4 changed files with 10 additions and 19 deletions
|
@ -32,8 +32,8 @@ static bool is_all_whitespace(StringView string)
|
|||
return true;
|
||||
}
|
||||
|
||||
// NOTE: This collapes whitespace into a single ASCII space if collapse is true. If previous_is_empty_or_ends_in_whitespace, it also strips leading whitespace.
|
||||
void TextNode::compute_text_for_rendering(bool collapse, bool previous_is_empty_or_ends_in_whitespace)
|
||||
// NOTE: This collapses whitespace into a single ASCII space if collapse is true.
|
||||
void TextNode::compute_text_for_rendering(bool collapse)
|
||||
{
|
||||
auto& data = dom_node().data();
|
||||
if (!collapse || data.is_empty()) {
|
||||
|
@ -44,12 +44,8 @@ void TextNode::compute_text_for_rendering(bool collapse, bool previous_is_empty_
|
|||
// NOTE: A couple fast returns to avoid unnecessarily allocating a StringBuilder.
|
||||
if (data.length() == 1) {
|
||||
if (is_ascii_space(data[0])) {
|
||||
if (previous_is_empty_or_ends_in_whitespace)
|
||||
m_text_for_rendering = String::empty();
|
||||
else {
|
||||
static String s_single_space_string = " ";
|
||||
m_text_for_rendering = s_single_space_string;
|
||||
}
|
||||
static String s_single_space_string = " ";
|
||||
m_text_for_rendering = s_single_space_string;
|
||||
} else {
|
||||
m_text_for_rendering = data;
|
||||
}
|
||||
|
@ -76,8 +72,6 @@ void TextNode::compute_text_for_rendering(bool collapse, bool previous_is_empty_
|
|||
++index;
|
||||
};
|
||||
|
||||
if (previous_is_empty_or_ends_in_whitespace)
|
||||
skip_over_whitespace();
|
||||
while (index < data.length()) {
|
||||
if (is_ascii_space(data[index])) {
|
||||
builder.append(' ');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue