pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1719705 - in /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap: CMap.java CodespaceRange.java
Date Sat, 12 Dec 2015 15:45:43 GMT
Author: lehmi
Date: Sat Dec 12 15:45:43 2015
New Revision: 1719705

URL: http://svn.apache.org/viewvc?rev=1719705&view=rev
Log:
PDFBOX-3151: replace List<byte> with byte[] as proposed by Philip Helger

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java?rev=1719705&r1=1719704&r2=1719705&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java Sat Dec 12 15:45:43
2015
@@ -104,15 +104,16 @@ public class CMap
         in.mark(4);
 
         // mapping algorithm
-        List<Byte> bytes = new ArrayList<Byte>(4);
+        byte[] bytes = new byte[4];
         for (int i = 0; i < 4; i++)
         {
-            bytes.add((byte)in.read());
+            bytes[i] = (byte)in.read();
+            final int byteCount = i+1;
             for (CodespaceRange range : codespaceRanges)
             {
-                if (range.isFullMatch(bytes))
+                if (range.isFullMatch(bytes, byteCount))
                 {
-                    return toInt(bytes);
+                    return toInt(bytes, byteCount);
                 }
             }
         }
@@ -121,15 +122,16 @@ public class CMap
         in.reset();
 
         // modified mapping algorithm
-        bytes = new ArrayList<Byte>(4);
         for (int i = 0; i < 4; i++)
         {
-            bytes.add((byte)in.read());
+            final byte curByte = (byte)in.read(); 
+            bytes[i] = curByte;
+            final int byteCount = i + 1;
             CodespaceRange match = null;
             CodespaceRange shortest = null;
             for (CodespaceRange range : codespaceRanges)
             {
-                if (range.isPartialMatch(bytes.get(i), i))
+                if (range.isPartialMatch(curByte, i))
                 {
                     if (match == null)
                     {
@@ -156,9 +158,9 @@ public class CMap
             }
 
             // we're done when we have enough bytes for the matched range
-            if (match != null && match.getStart().length == bytes.size())
+            if (match != null && match.getStart().length == byteCount)
             {
-                return toInt(bytes);
+                return toInt(bytes, byteCount);
             }
         }
 
@@ -166,15 +168,15 @@ public class CMap
     }
 
     /**
-     * Returns an int given a List<Byte>
+     * Returns an int for the given a byte array
      */
-    private int toInt(List<Byte> data)
+    private int toInt(byte[] data, int dataLen)
     {
         int code = 0;
-        for (byte b : data)
+        for (int i = 0; i < dataLen; ++i)
         {
             code <<= 8;
-            code |= (b + 256) % 256;
+            code |= (data[i] + 256) % 256;
         }
         return code;
     }

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java?rev=1719705&r1=1719704&r2=1719705&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java Sat Dec
12 15:45:43 2015
@@ -16,7 +16,6 @@
  */
 package org.apache.fontbox.cmap;
 
-import java.util.List;
 
 /**
  * This represents a single entry in the codespace range.
@@ -99,17 +98,17 @@ public class CodespaceRange
     /**
      * Returns true if the given code bytes match this codespace range.
      */
-    public boolean isFullMatch(List<Byte> code)
+    public boolean isFullMatch(byte[] code, int codeLen)
     {
         // code must be the same length as the bounding codes
-        if (code.size() >= start.length && code.size() <= end.length)
+        if (codeLen >= start.length && codeLen <= end.length)
         {
             // each of it bytes must lie between the corresponding bytes of the upper &
lower bounds
-            for (int i = 0; i < code.size(); i++)
+            for (int i = 0; i < codeLen; i++)
             {
                 int startNum = start[i] & 0xff;
                 int endNum = end[i] & 0xff;
-                int codeNum = code.get(i) & 0xff;
+                int codeNum = code[i] & 0xff;
 
                 if (codeNum > endNum || codeNum < startNum)
                 {
@@ -120,7 +119,7 @@ public class CodespaceRange
         }
         return false;
     }
-
+    
     /**
      * Returns true if the given byte matches the byte at the given index of this codespace
range.
      */



Mime
View raw message