Skip to content

Commit

Permalink
eclipse-platform#414: slow StyledTextRenderer for unicode and unprint…
Browse files Browse the repository at this point in the history
…able control characters

This test replaces the characters 0x00-0x1F with some alternative
character (by default ' ') for rendering. This improves the performance
significantly.
  • Loading branch information
Thomas Singer committed Aug 28, 2024
1 parent 9248e1e commit 1f5d403
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2854,6 +2854,13 @@ public boolean isDisposed () {
return device == null;
}

private char replaceBelowSpaceCharacters(char chr) {
return chr >= ' '
? chr
//: (char)(0x2400 + chr);
: ' ';
}

/*
* Itemize the receiver text
*/
Expand Down Expand Up @@ -2895,8 +2902,11 @@ StyleItem[] itemize () {
*/
for (int i = 0, latestNeutralIndex = -2, latestUnicodeIndex = -2; i < length; i++) {
char c = chars[i];
if (c < ' ') {
c = replaceBelowSpaceCharacters(c);
}

if (c >= ' ' && c <= '~' && !Character.isAlphabetic(c)) {
if (c <= '~' && !Character.isAlphabetic(c)) {
latestNeutralIndex = i;
} else if (c > 255) {
latestUnicodeIndex = i;
Expand Down Expand Up @@ -3740,6 +3750,9 @@ void shape (GC gc, final long hdc, final StyleItem run) {
final int[] buffer = new int[1];
final char[] chars = new char[run.length];
segmentsText.getChars(run.start, run.start + run.length, chars, 0);
for (int i = 0; i < chars.length; i++) {
chars[i] = replaceBelowSpaceCharacters(chars[i]);
}

final int maxGlyphs = (chars.length * 3 / 2) + 16;
long hHeap = OS.GetProcessHeap();
Expand Down

0 comments on commit 1f5d403

Please sign in to comment.