Skip to content

Commit

Permalink
use LinkedHashMap instead of HashMap
Browse files Browse the repository at this point in the history
Only store the pointer to the utf8 string if its creation was successful
  • Loading branch information
johanvos committed Jun 12, 2020
1 parent 998f55c commit 0d6e909
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.sun.javafx.text.TextRun;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

class PangoGlyphLayout extends GlyphLayout {
Expand Down Expand Up @@ -84,7 +84,7 @@ private boolean check(long checkValue, String message, long context, long desc,
return true;
}

private Map<TextRun, Long> runUtf8 = new HashMap<>();
private Map<TextRun, Long> runUtf8 = new LinkedHashMap<>();
public void layout(TextRun run, PGFont font, FontStrike strike, char[] text) {
/* Create the pango font and attribute list */
FontResource fr = font.getFontResource();
Expand Down Expand Up @@ -133,10 +133,10 @@ public void layout(TextRun run, PGFont font, FontStrike strike, char[] text) {
if (str == null) {
char[] rtext = Arrays.copyOfRange(text, run.getStart(), run.getEnd());
str = OSPango.g_utf16_to_utf8(rtext);
runUtf8.put(run, str);
if (check(str, "Failed allocating UTF-8 buffer.", context, desc, attrList)) {
return;
}
runUtf8.put(run, str);
}

/* Itemize */
Expand Down

0 comments on commit 0d6e909

Please sign in to comment.