Skip to content

Commit

Permalink
IJPL-159869 Improve performance of decodeUsingGraphicalState
Browse files Browse the repository at this point in the history
Do not create a new array for most of the mapped characters.
`new Object[]{mappedChar, null}` consumed a significant time.
  • Loading branch information
KonstantinHudyakov committed Aug 8, 2024
1 parent 3e760c3 commit bdf25fd
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions core/src/com/jediterm/terminal/emulator/charset/CharacterSets.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jediterm.terminal.emulator.charset;

import com.jediterm.terminal.util.CharUtils;
import org.jetbrains.annotations.Nullable;

/**
* Provides the (graphical) character sets.
Expand Down Expand Up @@ -177,9 +178,7 @@ private CharacterSets() {
* @return the mapped character.
*/
public static char getChar(char original, GraphicSet gl, GraphicSet gr) {
Object[] mapping = getMapping(original, gl, gr);

int ch = (Integer) mapping[0];
int ch = getMappedChar(original, gl, gr);
if (ch > 0) {
return (char)ch;
}
Expand All @@ -197,14 +196,8 @@ public static char getChar(char original, GraphicSet gl, GraphicSet gr) {
* @return the character name.
*/
public static String getCharName(char original, GraphicSet gl, GraphicSet gr) {
Object[] mapping = getMapping(original, gl, gr);

String name = (String)mapping[1];
if (name == null) {
name = String.format("<%d>", (int)original);
}

return name;
Object[] cMapping = getCMapping(original);
return cMapping != null ? (String) cMapping[1] : String.format("<%d>", (int) original);
}

/**
Expand All @@ -216,29 +209,37 @@ public static String getCharName(char original, GraphicSet gl, GraphicSet gr) {
* @param gr the GR graphic set, cannot be <code>null</code>.
* @return the mapped character.
*/
private static Object[] getMapping(char original, GraphicSet gl, GraphicSet gr) {
int mappedChar = original;
if (original >= C0_START && original <= C0_END) {
int idx = original - C0_START;
return C0_CHARS[idx];
}
else if (original >= C1_START && original <= C1_END) {
int idx = original - C1_START;
return C1_CHARS[idx];
private static int getMappedChar(char original, GraphicSet gl, GraphicSet gr) {
Object[] cMapping = getCMapping(original);
if (cMapping != null) {
return (int) cMapping[0];
}
else if (original >= GL_START && original <= GL_END) {
int idx = original - GL_START;
mappedChar = gl.map(original, idx);
}
return gl.map(original, idx);
}
//To support UTF-8 we don't use GR table
//TODO: verify that approach

//else if (original >= GR_START && original <= GR_END) {
// int idx = original - GR_START;
// mappedChar = gr.map(original, idx);
// return gr.map(original, idx);
//}
else {
return original;
}
}

return new Object[]{mappedChar, null};
private static @Nullable Object[] getCMapping(char original) {
if (original >= C0_START && original <= C0_END) {
int idx = original - C0_START;
return C0_CHARS[idx];
}
else if (original >= C1_START && original <= C1_END) {
int idx = original - C1_START;
return C1_CHARS[idx];
}
return null;
}
}

0 comments on commit bdf25fd

Please sign in to comment.