Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOB-10804] Rework append for better memory efficiency #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ public Template visitBody(final BodyContext ctx) {
list.add(candidate);
prev = candidate;
} else {
((Text) prev).append(((Text) candidate).textWithoutEscapeChar());
((Text) prev).append(((Text) candidate));
}
} else {
list.add(candidate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class Text extends BaseTemplate {
/**
* The plain text. Required.
*/
private StringBuilder text;
private final StringBuilder text;

/** The escape's char or empty. */
private String escapeChar;
private final String escapeChar;

/**
* Creates a new {@link Text}.
Expand Down Expand Up @@ -67,27 +67,21 @@ public String text() {
return escapeChar + text.toString();
}

/**
* @return Same as {@link #text()} without the escape char.
*/
public char[] textWithoutEscapeChar() {
return text.toString().toCharArray();
}

@Override
protected void merge(final Context scope, final Writer writer) throws IOException {
writer.write(text.toString());
}

/**
* Append text.
* Merges the content of the given {@link Text} instance into this instance.
*
* @param text The text to append.
* @return This object.
* @param other the {@link Text} instance to merge with this instance;
* if null or contains no text, no action is taken
*/
public Text append(final char[] text) {
this.text.append(text);
return this;
}
public void append(final Text other) {
if (other != null && other.text != null) {
this.text.append(other.text);
}
}

}