Skip to content

Commit

Permalink
PDFBOX-5660: Simplify list and map operations, use known size when cr…
Browse files Browse the repository at this point in the history
…eating StringBuilder, by Axel Howind

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1914574 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Dec 12, 2023
1 parent dae854c commit da7b275
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ private List<Integer> applyGsubFeature(ScriptFeature scriptFeature, List<Integer

private List<Integer> getBeforeHalfGlyphIds()
{
List<Integer> glyphIds = new ArrayList<>();
glyphIds.add(getGlyphId(BEFORE_HALF_CHAR));
return Collections.unmodifiableList(glyphIds);
return List.of(getGlyphId(BEFORE_HALF_CHAR));
}

private List<Integer> getRephGlyphIds()
Expand Down
14 changes: 3 additions & 11 deletions pdfbox/src/main/java/org/apache/pdfbox/cos/PDFDocEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private static void set(int code, char unicode)
*/
public static String toString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(bytes.length);
for (byte b : bytes)
{
if ((b & 0xff) >= CODE_TO_UNI.length)
Expand All @@ -140,18 +140,10 @@ public static String toString(byte[] bytes)
*/
public static byte[] getBytes(String text)
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream(text.length());
for (char c : text.toCharArray())
{
Integer code = UNI_TO_CODE.get(c);
if (code == null)
{
out.write(0);
}
else
{
out.write(code);
}
out.write(UNI_TO_CODE.getOrDefault(c, 0));
}
return out.toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,9 @@ private void addSubstitutes(String match, List<String> replacements)
*/
private List<String> getSubstitutes(String postScriptName)
{
List<String> subs = substitutes.get(postScriptName.replace(" ", "").toLowerCase(Locale.ENGLISH));
if (subs != null)
{
return subs;
}
else
{
return Collections.emptyList();
}
return substitutes.getOrDefault(
postScriptName.replace(" ", "").toLowerCase(Locale.ENGLISH),
Collections.emptyList());
}

/**
Expand Down

0 comments on commit da7b275

Please sign in to comment.